Bug 1338534 - [mozlog] Log message and stack for failures when using pytest-mozlog with pytest-xdist. r?ahal
When using pytest-xdist to run tests in parallel, failures are serialised as strings. This means we're unable to reliably extract the message and line number, so instead we log the stack and the message as the serialised string result.
MozReview-Commit-ID: 6vrEjBtkXK8
--- a/testing/mozbase/mozlog/mozlog/pytest_mozlog/plugin.py
+++ b/testing/mozbase/mozlog/mozlog/pytest_mozlog/plugin.py
@@ -79,19 +79,23 @@ class MozLog(object):
# If an xfail unexpectedly passes, the 'call' report has .failed (Pytest 2)
# or .passed (Pytest 3), so we leave status as PASS (!= expected)
# to log an unexpected result.
expected = 'FAIL'
if report.skipped: # indicates expected failure (passing test)
status = 'FAIL'
elif report.failed:
status = 'FAIL' if report.when == 'call' else 'ERROR'
- crash = report.longrepr.reprcrash # here longrepr is a ReprExceptionInfo
- message = "{0} (line {1})".format(crash.message, crash.lineno)
- stack = report.longrepr.reprtraceback
+ try:
+ crash = report.longrepr.reprcrash # here longrepr is a ReprExceptionInfo
+ message = "{0} (line {1})".format(crash.message, crash.lineno)
+ stack = report.longrepr.reprtraceback
+ except AttributeError:
+ # When using pytest-xdist, longrepr is serialised as a str
+ message = stack = report.longrepr
elif report.skipped: # indicates true skip
status = expected = 'SKIP'
message = report.longrepr[-1] # here longrepr is a tuple (file, lineno, reason)
if status != expected or expected != 'PASS':
self.results[test] = (status, expected, message, stack)
if report.when == 'teardown':
defaults = ('PASS', 'PASS', None, None)
status, expected, message, stack = self.results.get(test, defaults)