Bug 801679 - Handle expected failures and skipped tests in mozunit runner. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 12 Feb 2016 12:21:05 +0900
changeset 284420 199a9500951dc2d14329b95ff7265aa5712cf966
parent 284419 12b3f2e6e3e19d2db21b9a6de8f1eb1de3421cf1
child 284421 17132c8ff5f4b67b319478899a8e0763448337e1
push idunknown
push userunknown
push dateunknown
reviewersgps
bugs801679
milestone47.0a1
Bug 801679 - Handle expected failures and skipped tests in mozunit runner. r=gps Python's unittest has decorators to mark tests as skipped or expecting to fail. Mozunit runner fails to print anything for them. While here, somehow unify the output for TEST-UNEXPECTED-FAIL. This leaves known failures silent about the failure. It would be better to only show them with a flag, like -v, and to leave it to a followup.
config/mozunit.py
--- a/config/mozunit.py
+++ b/config/mozunit.py
@@ -27,21 +27,41 @@ class _MozTestResult(_TestResult):
         self.descriptions = descriptions
 
     def getDescription(self, test):
         if self.descriptions:
             return test.shortDescription() or str(test)
         else:
             return str(test)
 
+    def printStatus(self, status, test, message=''):
+        line = "{status} | {file} | {test}{sep}{message}".format(
+            status=status,
+            file=inspect.getfile(test.__class__),
+            test=test._testMethodName,
+            sep=', ' if message else '',
+            message=message,
+        )
+        self.stream.writeln(line)
+
     def addSuccess(self, test):
         _TestResult.addSuccess(self, test)
-        filename = inspect.getfile(test.__class__)
-        testname = test._testMethodName
-        self.stream.writeln("TEST-PASS | {0} | {1}".format(filename, testname))
+        self.printStatus('TEST-PASS', test)
+
+    def addSkip(self, test, reason):
+        _TestResult.addSkip(self, test, reason)
+        self.printStatus('TEST-SKIP', test)
+
+    def addExpectedFailure(self, test, err):
+        _TestResult.addExpectedFailure(self, test, err)
+        self.printStatus('TEST-KNOWN-FAIL', test)
+
+    def addUnexpectedSuccess(self, test):
+        _TestResult.addUnexpectedSuccess(self, test)
+        self.printStatus('TEST-UNEXPECTED-PASS', test)
 
     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):
@@ -53,18 +73,18 @@ class _MozTestResult(_TestResult):
     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))
+        self.printStatus('TEST-UNEXPECTED-FAIL', test,
+                         'line {0}: {1}'.format(_ln, value.message))
 
 
 class MozTestRunner(_TestRunner):
     def _makeResult(self):
         return _MozTestResult(self.stream, self.descriptions)
     def run(self, test):
         result = self._makeResult()
         test(result)