Bug 1338534 - [mozlog] Log message and stack for failures when using pytest-mozlog with pytest-xdist. r?ahal draft
authorDave Hunt <dhunt@mozilla.com>
Tue, 14 Feb 2017 12:13:11 +0000
changeset 485055 88f55c5a10d4f671e258dcfbf13ecc9f494cf832
parent 484998 e9b926463f9ea76b836ebecd824506e1febee19e
child 485056 6c5f52c5c839f50597cffc7dce60f02cbbb8db5e
push id45612
push userdhunt@mozilla.com
push dateThu, 16 Feb 2017 01:41:44 +0000
reviewersahal
bugs1338534
milestone54.0a1
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
testing/mozbase/mozlog/mozlog/pytest_mozlog/plugin.py
--- 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)