Skip to content

Commit 606db78

Browse files
committed
pass in an infoclass to resultclass
... in case you need to subclass _TestInfo. (e.g. pull request #98)
1 parent 887df0d commit 606db78

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

xmlrunner/result.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class _XMLTestResult(_TextTestResult):
140140
Used by XMLTestRunner.
141141
"""
142142
def __init__(self, stream=sys.stderr, descriptions=1, verbosity=1,
143-
elapsed_times=True, properties=None):
143+
elapsed_times=True, properties=None, infoclass=None):
144144
_TextTestResult.__init__(self, stream, descriptions, verbosity)
145145
self.buffer = True # we are capturing test output
146146
self._stdout_data = None
@@ -149,11 +149,15 @@ def __init__(self, stream=sys.stderr, descriptions=1, verbosity=1,
149149
self.callback = None
150150
self.elapsed_times = elapsed_times
151151
self.properties = properties # junit testsuite properties
152+
if infoclass is None:
153+
self.infoclass = _TestInfo
154+
else:
155+
self.infoclass = infoclass
152156

153157
def _prepare_callback(self, test_info, target_list, verbose_str,
154158
short_str):
155159
"""
156-
Appends a _TestInfo to the given target list and sets a callback
160+
Appends a `infoclass` to the given target list and sets a callback
157161
method to be called by stopTest method.
158162
"""
159163
target_list.append(test_info)
@@ -218,7 +222,7 @@ def addSuccess(self, test):
218222
"""
219223
self._save_output_data()
220224
self._prepare_callback(
221-
_TestInfo(self, test), self.successes, 'OK', '.'
225+
self.infoclass(self, test), self.successes, 'OK', '.'
222226
)
223227

224228
@failfast
@@ -227,7 +231,8 @@ def addFailure(self, test, err):
227231
Called when a test method fails.
228232
"""
229233
self._save_output_data()
230-
testinfo = _TestInfo(self, test, _TestInfo.FAILURE, err)
234+
testinfo = self.infoclass(
235+
self, test, self.infoclass.FAILURE, err)
231236
self.failures.append((
232237
testinfo,
233238
self._exc_info_to_string(err, test)
@@ -240,7 +245,8 @@ def addError(self, test, err):
240245
Called when a test method raises an error.
241246
"""
242247
self._save_output_data()
243-
testinfo = _TestInfo(self, test, _TestInfo.ERROR, err)
248+
testinfo = self.infoclass(
249+
self, test, self.infoclass.ERROR, err)
244250
self.errors.append((
245251
testinfo,
246252
self._exc_info_to_string(err, test)
@@ -253,7 +259,8 @@ def addSubTest(self, testcase, test, err):
253259
"""
254260
if err is not None:
255261
self._save_output_data()
256-
testinfo = _TestInfo(self, testcase, _TestInfo.ERROR, err, subTest=test)
262+
testinfo = self.infoclass(
263+
self, testcase, self.infoclass.ERROR, err, subTest=test)
257264
self.errors.append((
258265
testinfo,
259266
self._exc_info_to_string(err, testcase)
@@ -265,7 +272,8 @@ def addSkip(self, test, reason):
265272
Called when a test method was skipped.
266273
"""
267274
self._save_output_data()
268-
testinfo = _TestInfo(self, test, _TestInfo.SKIP, reason)
275+
testinfo = self.infoclass(
276+
self, test, self.infoclass.SKIP, reason)
269277
self.skipped.append((testinfo, reason))
270278
self._prepare_callback(testinfo, [], 'SKIP', 'S')
271279

@@ -329,10 +337,10 @@ def _report_testsuite(suite_name, tests, xml_document, parentElement,
329337
testsuite.setAttribute(
330338
'time', '%.3f' % sum(map(lambda e: e.elapsed_time, tests))
331339
)
332-
failures = filter(lambda e: e.outcome == _TestInfo.FAILURE, tests)
340+
failures = filter(lambda e: e.outcome == e.FAILURE, tests)
333341
testsuite.setAttribute('failures', str(len(list(failures))))
334342

335-
errors = filter(lambda e: e.outcome == _TestInfo.ERROR, tests)
343+
errors = filter(lambda e: e.outcome == e.ERROR, tests)
336344
testsuite.setAttribute('errors', str(len(list(errors))))
337345

338346
_XMLTestResult._report_testsuite_properties(
@@ -404,11 +412,11 @@ def _report_testcase(test_result, xml_testsuite, xml_document):
404412
)
405413
testcase.setAttribute('time', '%.3f' % test_result.elapsed_time)
406414

407-
if (test_result.outcome != _TestInfo.SUCCESS):
415+
if (test_result.outcome != test_result.SUCCESS):
408416
elem_name = ('failure', 'error', 'skipped')[test_result.outcome-1]
409417
failure = xml_document.createElement(elem_name)
410418
testcase.appendChild(failure)
411-
if test_result.outcome != _TestInfo.SKIP:
419+
if test_result.outcome != test_result.SKIP:
412420
failure.setAttribute(
413421
'type',
414422
safe_unicode(test_result.err[0].__name__)

0 commit comments

Comments
 (0)