changeset 21429:203ed3cf6c81

run-tests: define custom result and runner classes for unittest We need to teach unittest about some custom result types. This will require some custom classes. This patch creates a skeleton for them.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 20 Apr 2014 11:47:40 -0700
parents 3df2ecf8d545
children cf2992656bf8
files tests/run-tests.py
diffstat 1 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Sun Apr 20 11:29:39 2014 -0700
+++ b/tests/run-tests.py	Sun Apr 20 11:47:40 2014 -0700
@@ -982,6 +982,19 @@
 
 iolock = threading.Lock()
 
+class TestResult(unittest._TextTestResult):
+    """Holds results when executing via unittest."""
+    # Don't worry too much about accessing the non-public _TextTestResult.
+    # It is relatively common in Python testing tools.
+    def __init__(self, *args, **kwargs):
+        super(TestResult, self).__init__(*args, **kwargs)
+
+class TextTestRunner(unittest.TextTestRunner):
+    """Custom unittest test runner that uses appropriate settings."""
+
+    def _makeResult(self):
+        return TestResult(self.stream, self.descriptions, self.verbosity)
+
 class TestRunner(object):
     """Holds context for executing tests.
 
@@ -1191,7 +1204,7 @@
                 verbosity = 1
                 if self.options.verbose:
                     verbosity = 2
-                runner = unittest.TextTestRunner(verbosity=verbosity)
+                runner = TextTestRunner(verbosity=verbosity)
                 runner.run(suite)
             else:
                 self._executetests(tests)