| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| """TestResult implementing default output for test execution status.""" |
|
|
| import unittest |
|
|
|
|
| class TextTestResult(unittest.TextTestResult): |
| """TestResult class that provides the default text result formatting.""" |
|
|
| def __init__(self, stream, descriptions, verbosity): |
| |
| |
| super().__init__(stream, descriptions, 0) |
| self._per_test_output = verbosity > 0 |
|
|
| def _print_status(self, tag, test, reason=None): |
| if self._per_test_output: |
| test_id = test.id() |
| if test_id.startswith('__main__.'): |
| test_id = test_id[len('__main__.'):] |
| if reason: |
| print('[%s] %s - %s' % (tag, test_id, reason), file=self.stream) |
| else: |
| print('[%s] %s' % (tag, test_id), file=self.stream) |
| self.stream.flush() |
|
|
| def startTest(self, test): |
| super().startTest(test) |
| self._print_status(' RUN ', test) |
|
|
| def addSuccess(self, test): |
| super().addSuccess(test) |
| self._print_status(' OK ', test) |
|
|
| def addError(self, test, err): |
| super().addError(test, err) |
| self._print_status(' FAILED ', test) |
|
|
| def addFailure(self, test, err): |
| super().addFailure(test, err) |
| self._print_status(' FAILED ', test) |
|
|
| def addSkip(self, test, reason): |
| super().addSkip(test, reason) |
| self._print_status(' SKIPPED ', test, reason) |
|
|
| def addExpectedFailure(self, test, err): |
| super().addExpectedFailure(test, err) |
| self._print_status(' OK ', test) |
|
|
| def addUnexpectedSuccess(self, test): |
| super().addUnexpectedSuccess(test) |
| self._print_status(' FAILED ', test) |
|
|
|
|
| class TextTestRunner(unittest.TextTestRunner): |
| """A test runner that produces formatted text results.""" |
|
|
| _TEST_RESULT_CLASS = TextTestResult |
|
|
| |
| |
| |
| |
| run_for_debugging = False |
|
|
| def run(self, test) -> unittest.TextTestResult: |
| if self.run_for_debugging: |
| return self._run_debug(test) |
| else: |
| return super().run(test) |
|
|
| def _run_debug(self, test) -> unittest.TextTestResult: |
| test.debug() |
| |
| return self._makeResult() |
|
|
| def _makeResult(self): |
| return TextTestResult(self.stream, self.descriptions, self.verbosity) |
|
|