|
18 | 18 |
|
19 | 19 | import testtools |
20 | 20 | from testtools.matchers import EndsWith |
21 | | -from testtools.tests.helpers import LoggingResult |
22 | 21 |
|
23 | 22 | import testscenarios |
24 | 23 |
|
25 | 24 |
|
| 25 | +class LoggingResult(testtools.TestResult): |
| 26 | + """TestResult that logs its event to a list.""" |
| 27 | + |
| 28 | + def __init__(self, log): |
| 29 | + self._events = log |
| 30 | + super().__init__() |
| 31 | + |
| 32 | + def startTest(self, test): |
| 33 | + self._events.append(("startTest", test)) |
| 34 | + super().startTest(test) |
| 35 | + |
| 36 | + def stop(self): |
| 37 | + self._events.append("stop") |
| 38 | + super().stop() |
| 39 | + |
| 40 | + def stopTest(self, test): |
| 41 | + self._events.append(("stopTest", test)) |
| 42 | + super().stopTest(test) |
| 43 | + |
| 44 | + def addFailure(self, test, err=None, details=None): |
| 45 | + self._events.append(("addFailure", test, err)) |
| 46 | + super().addFailure(test, err, details) |
| 47 | + |
| 48 | + def addError(self, test, err=None, details=None): |
| 49 | + self._events.append(("addError", test, err)) |
| 50 | + super().addError(test, err, details) |
| 51 | + |
| 52 | + def addSkip(self, test, reason=None, details=None): |
| 53 | + # Extract reason from details if not provided directly |
| 54 | + if reason is None and details and "reason" in details: |
| 55 | + reason = details["reason"].as_text() |
| 56 | + self._events.append(("addSkip", test, reason)) |
| 57 | + super().addSkip(test, reason, details) |
| 58 | + |
| 59 | + def addSuccess(self, test, details=None): |
| 60 | + self._events.append(("addSuccess", test)) |
| 61 | + super().addSuccess(test, details) |
| 62 | + |
| 63 | + def startTestRun(self): |
| 64 | + self._events.append("startTestRun") |
| 65 | + super().startTestRun() |
| 66 | + |
| 67 | + def stopTestRun(self): |
| 68 | + self._events.append("stopTestRun") |
| 69 | + super().stopTestRun() |
| 70 | + |
| 71 | + def done(self): |
| 72 | + self._events.append("done") |
| 73 | + super().done() |
| 74 | + |
| 75 | + def tags(self, new_tags, gone_tags): |
| 76 | + self._events.append(("tags", new_tags, gone_tags)) |
| 77 | + super().tags(new_tags, gone_tags) |
| 78 | + |
| 79 | + def time(self, a_datetime): |
| 80 | + self._events.append(("time", a_datetime)) |
| 81 | + super().time(a_datetime) |
| 82 | + |
| 83 | + |
26 | 84 | class TestTestWithScenarios(testtools.TestCase): |
27 | 85 | scenarios = testscenarios.scenarios.per_module_scenarios( |
28 | 86 | "impl", (("unittest", "unittest"), ("unittest2", "unittest2")) |
|
0 commit comments