Skip to content

Commit b863a76

Browse files
authored
Merge pull request #17 from testing-cabal/testtools-compat
Fix compatibility with newer testtools
2 parents be7882c + 75b76e7 commit b863a76

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

testscenarios/tests/test_testcase.py

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,69 @@
1818

1919
import testtools
2020
from testtools.matchers import EndsWith
21-
from testtools.tests.helpers import LoggingResult
2221

2322
import testscenarios
2423

2524

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+
2684
class TestTestWithScenarios(testtools.TestCase):
2785
scenarios = testscenarios.scenarios.per_module_scenarios(
2886
"impl", (("unittest", "unittest"), ("unittest2", "unittest2"))

0 commit comments

Comments
 (0)