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.
--- 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)