Bug 795681 - Print out failures in mozunit runner. r=gps draft
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 12 Feb 2016 12:16:17 +0900
changeset 330625 687f4ed7ef41c8a3cced558422bd046b724e69ad
parent 330624 c2efabe8fab11e8d03316678f9958a6192b34dfa
child 330626 6f21334856639ffd4eea714b3ac401b72a1e8b29
push id10785
push userbmo:mh+mozilla@glandium.org
push dateFri, 12 Feb 2016 03:33:27 +0000
reviewersgps
bugs795681
milestone47.0a1
Bug 795681 - Print out failures in mozunit runner. r=gps Python's unittest separates errors and failures, where the former is uncaught exceptions and the latter uncaught assertions. We were only printing the former, making the mozunit runner output useless to debug failures due to assertions in the code being tested. I would usually edit the test to temporarily switch to unittest.main(). Enough is enough, handle failures properly. At the same time, instead of printing all the errors one after the other at the end, print them right after the TEST-UNEXPECTED-FAIL message.
config/mozunit.py
--- a/config/mozunit.py
+++ b/config/mozunit.py
@@ -36,45 +36,43 @@ class _MozTestResult(_TestResult):
         _TestResult.addSuccess(self, test)
         filename = inspect.getfile(test.__class__)
         testname = test._testMethodName
         self.stream.writeln("TEST-PASS | {0} | {1}".format(filename, testname))
 
     def addError(self, test, err):
         _TestResult.addError(self, test, err)
         self.printFail(test, err)
+        self.stream.writeln("ERROR: {0}".format(self.getDescription(test)))
+        self.stream.writeln(self.errors[-1][1])
 
     def addFailure(self, test, err):
         _TestResult.addFailure(self, test, err)
         self.printFail(test,err)
+        self.stream.writeln("FAIL: {0}".format(self.getDescription(test)))
+        self.stream.writeln(self.failures[-1][1])
 
     def printFail(self, test, err):
         exctype, value, tb = err
         # Skip test runner traceback levels
         while tb and self._is_relevant_tb_level(tb):
             tb = tb.tb_next
         if not tb:
             self.stream.writeln("TEST-UNEXPECTED-FAIL | NO TRACEBACK |")
         _f, _ln, _t = inspect.getframeinfo(tb)[:3]
         self.stream.writeln("TEST-UNEXPECTED-FAIL | {0} | line {1}, {2}: {3}" 
                             .format(_f, _ln, _t, value.message))
 
-    def printErrorList(self):
-        for test, err in self.errors:
-            self.stream.writeln("ERROR: {0}".format(self.getDescription(test)))
-            self.stream.writeln("{0}".format(err))
-
 
 class MozTestRunner(_TestRunner):
     def _makeResult(self):
         return _MozTestResult(self.stream, self.descriptions)
     def run(self, test):
         result = self._makeResult()
         test(result)
-        result.printErrorList()
         return result
 
 class MockedFile(StringIO):
     def __init__(self, context, filename, content = ''):
         self.context = context
         self.name = filename
         StringIO.__init__(self, content)