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.
--- 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)