# HG changeset patch # User Gregory Szorc # Date 1398019660 25200 # Node ID 203ed3cf6c81c33ee76bbfb9ec3951237fae1fb0 # Parent 3df2ecf8d54544ee7ca7ed79749b271bf5ba9cf4 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. diff -r 3df2ecf8d545 -r 203ed3cf6c81 tests/run-tests.py --- 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)