Skip to content

Commit 887df0d

Browse files
committed
add resultclass for runner instanciation
... as described in unittest's doc ... _makeResult can be overridden in subclasses or you can control the resultclass provided to the runner. This may help separate concerns w.r.t. integration with other pieces of code that want to hook into the test result reporting (e.g. pull request #98)
1 parent 15b1db9 commit 887df0d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

xmlrunner/runner.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class XMLTestRunner(TextTestRunner):
1616
"""
1717
def __init__(self, output='.', outsuffix=None, stream=sys.stderr,
1818
descriptions=True, verbosity=1, elapsed_times=True,
19-
failfast=False, buffer=False, encoding=UTF8):
19+
failfast=False, buffer=False, encoding=UTF8,
20+
resultclass=None):
2021
TextTestRunner.__init__(self, stream, descriptions, verbosity,
2122
failfast=failfast, buffer=buffer)
2223
self.verbosity = verbosity
@@ -28,13 +29,18 @@ def __init__(self, output='.', outsuffix=None, stream=sys.stderr,
2829
outsuffix = time.strftime("%Y%m%d%H%M%S")
2930
self.outsuffix = outsuffix
3031
self.elapsed_times = elapsed_times
32+
if resultclass is None:
33+
self.resultclass = _XMLTestResult
34+
else:
35+
self.resultclass = resultclass
3136

3237
def _make_result(self):
3338
"""
3439
Creates a TestResult object which will be used to store
3540
information about the executed tests.
3641
"""
37-
return _XMLTestResult(
42+
# override in subclasses if necessary.
43+
return self.resultclass(
3844
self.stream, self.descriptions, self.verbosity, self.elapsed_times
3945
)
4046

0 commit comments

Comments
 (0)