[wdspec] Include error message for setup and teardown failures.

Differential Revision: https://phabricator.services.mozilla.com/D122387

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1676085
gecko-commit: 64c0e09f64462ccbbccc18b80e46492683a5c82e
gecko-reviewers: jgraham, webdriver-reviewers
diff --git a/tools/wptrunner/wptrunner/executors/pytestrunner/runner.py b/tools/wptrunner/wptrunner/executors/pytestrunner/runner.py
index 50819a9..78da846 100644
--- a/tools/wptrunner/wptrunner/executors/pytestrunner/runner.py
+++ b/tools/wptrunner/wptrunner/executors/pytestrunner/runner.py
@@ -103,35 +103,34 @@
         if report.passed and report.when == "call":
             self.record_pass(report)
         elif report.failed:
+            # pytest outputs the stacktrace followed by an error message prefixed
+            # with "E   ", e.g.
+            #
+            #        def test_example():
+            #  >         assert "fuu" in "foobar"
+            #  > E       AssertionError: assert 'fuu' in 'foobar'
+            message = ""
+            for line in report.longreprtext.splitlines():
+                if line.startswith("E   "):
+                    message = line[1:].strip()
+                    break
+
             if report.when != "call":
-                self.record_error(report)
+                self.record_error(report, message)
             else:
-                self.record_fail(report)
+                self.record_fail(report, message)
         elif report.skipped:
             self.record_skip(report)
 
     def record_pass(self, report):
         self.record(report.nodeid, "PASS")
 
-    def record_fail(self, report):
-        # pytest outputs the stacktrace followed by an error message prefixed
-        # with "E   ", e.g.
-        #
-        #        def test_example():
-        #  >         assert "fuu" in "foobar"
-        #  > E       AssertionError: assert 'fuu' in 'foobar'
-        message = ""
-        for line in report.longreprtext.splitlines():
-            if line.startswith("E   "):
-                message = line[1:].strip()
-                break
-
+    def record_fail(self, report, message):
         self.record(report.nodeid, "FAIL", message=message, stack=report.longrepr)
 
-    def record_error(self, report):
+    def record_error(self, report, message):
         # error in setup/teardown
-        if report.when != "call":
-            message = "%s error" % report.when
+        message = "{} error: {}".format(report.when, message)
         self.record(report.nodeid, "ERROR", message, report.longrepr)
 
     def record_skip(self, report):