Mercurial > hg
comparison tests/run-tests.py @ 21459:d5945324b130
run-tests: print compatible output from TextTestRunner
Our unittest TextTestRunner now prints output similar to the output
from the default execution mode - the output people expect from
run-tests.py.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 20 Apr 2014 16:39:05 -0700 |
parents | c42219733f30 |
children | df580990507e |
comparison
equal
deleted
inserted
replaced
21458:c42219733f30 | 21459:d5945324b130 |
---|---|
1105 return result | 1105 return result |
1106 | 1106 |
1107 class TextTestRunner(unittest.TextTestRunner): | 1107 class TextTestRunner(unittest.TextTestRunner): |
1108 """Custom unittest test runner that uses appropriate settings.""" | 1108 """Custom unittest test runner that uses appropriate settings.""" |
1109 | 1109 |
1110 def _makeResult(self): | 1110 def __init__(self, runner, *args, **kwargs): |
1111 return TestResult(self.stream, self.descriptions, self.verbosity) | 1111 super(TextTestRunner, self).__init__(*args, **kwargs) |
1112 | |
1113 self._runner = runner | |
1114 | |
1115 def run(self, test): | |
1116 result = TestResult(self.stream, self.descriptions, self.verbosity) | |
1117 | |
1118 test(result) | |
1119 | |
1120 failed = len(result.failures) | |
1121 warned = len(result.warned) | |
1122 skipped = len(result.skipped) | |
1123 ignored = len(result.ignored) | |
1124 | |
1125 self.stream.writeln('') | |
1126 | |
1127 if not self._runner.options.noskips: | |
1128 for test, msg in result.skipped: | |
1129 self.stream.writeln('Skipped %s: %s' % (test.name, msg)) | |
1130 for test, msg in result.warned: | |
1131 self.stream.writeln('Warned %s: %s' % (test.name, msg)) | |
1132 for test, msg in result.failures: | |
1133 self.stream.writeln('Failed %s: %s' % (test.name, msg)) | |
1134 for test, msg in result.errors: | |
1135 self.stream.writeln('Errored %s: %s' % (test.name, msg)) | |
1136 | |
1137 self._runner._checkhglib('Tested') | |
1138 | |
1139 # This differs from unittest's default output in that we don't count | |
1140 # skipped and ignored tests as part of the total test count. | |
1141 self.stream.writeln('# Ran %d tests, %d skipped, %d warned, %d failed.' | |
1142 % (result.testsRun - skipped - ignored, | |
1143 skipped + ignored, warned, failed)) | |
1144 if failed: | |
1145 self.stream.writeln('python hash seed: %s' % | |
1146 os.environ['PYTHONHASHSEED']) | |
1147 if self._runner.options.time: | |
1148 self._runner._outputtimes() | |
1112 | 1149 |
1113 class TestRunner(object): | 1150 class TestRunner(object): |
1114 """Holds context for executing tests. | 1151 """Holds context for executing tests. |
1115 | 1152 |
1116 Tests rely on a lot of state. This object holds it for them. | 1153 Tests rely on a lot of state. This object holds it for them. |
1321 if self.options.unittest: | 1358 if self.options.unittest: |
1322 suite = TestSuite(self, tests=tests) | 1359 suite = TestSuite(self, tests=tests) |
1323 verbosity = 1 | 1360 verbosity = 1 |
1324 if self.options.verbose: | 1361 if self.options.verbose: |
1325 verbosity = 2 | 1362 verbosity = 2 |
1326 runner = TextTestRunner(verbosity=verbosity) | 1363 runner = TextTestRunner(self, verbosity=verbosity) |
1327 runner.run(suite) | 1364 runner.run(suite) |
1328 else: | 1365 else: |
1329 self._executetests(tests) | 1366 self._executetests(tests) |
1330 | 1367 |
1331 failed = len(self.results['!']) | 1368 failed = len(self.results['!']) |