Skip to content

Commit

Permalink
add resultclass for runner instanciation
Browse files Browse the repository at this point in the history
... 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)
  • Loading branch information
dnozay committed Feb 12, 2016
1 parent 15b1db9 commit 887df0d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions xmlrunner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class XMLTestRunner(TextTestRunner):
"""
def __init__(self, output='.', outsuffix=None, stream=sys.stderr,
descriptions=True, verbosity=1, elapsed_times=True,
failfast=False, buffer=False, encoding=UTF8):
failfast=False, buffer=False, encoding=UTF8,
resultclass=None):
TextTestRunner.__init__(self, stream, descriptions, verbosity,
failfast=failfast, buffer=buffer)
self.verbosity = verbosity
Expand All @@ -28,13 +29,18 @@ def __init__(self, output='.', outsuffix=None, stream=sys.stderr,
outsuffix = time.strftime("%Y%m%d%H%M%S")
self.outsuffix = outsuffix
self.elapsed_times = elapsed_times
if resultclass is None:
self.resultclass = _XMLTestResult
else:
self.resultclass = resultclass

def _make_result(self):
"""
Creates a TestResult object which will be used to store
information about the executed tests.
"""
return _XMLTestResult(
# override in subclasses if necessary.
return self.resultclass(
self.stream, self.descriptions, self.verbosity, self.elapsed_times
)

Expand Down

0 comments on commit 887df0d

Please sign in to comment.