Skip to content

Commit 3684921

Browse files
authored
[parallel_runner.py] Fix failure under XMLRunner (#25784)
With #25739 I inadvertently broke the handling of errors with the XML test runner.
1 parent 07af70b commit 3684921

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

test/parallel_testsuite.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,22 +260,34 @@ def addDuration(self, test, elapsed):
260260
def integrate_result(self, overall_results):
261261
"""This method get called on the main thread once the buffered result
262262
is received. It adds the buffered result to the overall result."""
263-
# The exception info objects that we are adding here have already
264-
# been turned into strings so make _exc_info_to_string into a no-op.
265-
overall_results._exc_info_to_string = lambda x, _y: x
263+
264+
# Turns a <test, string> pair back into something that looks enoough
265+
# link a <test, exc_info> pair. The exc_info tripple has the exception
266+
# type as its first element. This is needed in particilar in the
267+
# XMLTestRunner.
268+
def restore_exc_info(pair):
269+
test, exn_string = pair
270+
assert self.last_err_type, exn_string
271+
return (test, (self.last_err_type, exn_string, None))
272+
273+
# Our fame exc_info tripple keep the pre-serialized string in the
274+
# second element of the triple so we overide _exc_info_to_string
275+
# _exc_info_to_string to simply return it.
276+
overall_results._exc_info_to_string = lambda x, _y: x[1]
277+
266278
overall_results.startTest(self.test)
267279
if self.test_result == 'success':
268280
overall_results.addSuccess(self.test)
269281
elif self.test_result == 'failed':
270-
overall_results.addFailure(*self.failures[0])
282+
overall_results.addFailure(*restore_exc_info(self.failures[0]))
271283
elif self.test_result == 'errored':
272-
overall_results.addError(*self.errors[0])
284+
overall_results.addError(*restore_exc_info(self.errors[0]))
273285
elif self.test_result == 'skipped':
274286
overall_results.addSkip(*self.skipped[0])
275287
elif self.test_result == 'unexpected success':
276-
overall_results.addUnexpectedSuccess(*self.unexpectedSuccesses[0])
288+
overall_results.addUnexpectedSuccess(self.unexpectedSuccesses[0])
277289
elif self.test_result == 'expected failure':
278-
overall_results.addExpectedFailure(*self.expectedFailures[0])
290+
overall_results.addExpectedFailure(*restore_exc_info(self.expectedFailures[0]))
279291
else:
280292
assert False, f'unhandled test result {self.test_result}'
281293
overall_results.stopTest(self.test)
@@ -319,6 +331,7 @@ def addSuccess(self, test):
319331

320332
def addExpectedFailure(self, test, err):
321333
super().addExpectedFailure(test, err)
334+
self.last_err_type = err[0]
322335
self.test_result = 'expected failure'
323336

324337
def addUnexpectedSuccess(self, test):
@@ -331,10 +344,12 @@ def addSkip(self, test, reason):
331344

332345
def addFailure(self, test, err):
333346
super().addFailure(test, err)
347+
self.last_err_type = err[0]
334348
self.test_result = 'failed'
335349

336350
def addError(self, test, err):
337351
super().addError(test, err)
352+
self.last_err_type = err[0]
338353
self.test_result = 'errored'
339354

340355

0 commit comments

Comments
 (0)