From 10977a08dc430f8760f8089062bb688bb001fb23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juien=20Pag=C3=A8s?= Date: Wed, 21 May 2014 11:22:00 +0200 Subject: [PATCH] Bug 1003401 - Mozbase unit test logs should include test name in failures. r=dminor --- testing/mozbase/test.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/testing/mozbase/test.py b/testing/mozbase/test.py index 2ae54ee1241..181f5318eb1 100755 --- a/testing/mozbase/test.py +++ b/testing/mozbase/test.py @@ -23,6 +23,23 @@ from moztest.results import TestResultCollection here = os.path.dirname(os.path.abspath(__file__)) + +class TBPLTextTestResult(unittest.TextTestResult): + """ + Format the failure outputs according to TBPL. See: + https://wiki.mozilla.org/Sheriffing/Job_Visibility_Policy#6.29_Outputs_failures_in_a_TBPL-starrable_format + """ + + def addFailure(self, test, err): + super(unittest.TextTestResult, self).addFailure(test, err) + self.stream.writeln() + self.stream.writeln('TEST-UNEXPECTED-FAIL | %s | %s' % (test.id(), err[1])) + + def addUnexpectedSuccess(self, test): + super(unittest.TextTestResult, self).addUnexpectedSuccess(test) + self.stream.writeln() + self.stream.writeln('TEST-UNEXPECTED-PASS | %s | Unexpected pass' % test.id()) + def unittests(path): """return the unittests in a .py file""" @@ -85,7 +102,8 @@ def main(args=sys.argv[1:]): # run the tests suite = unittest.TestSuite(unittestlist) - runner = unittest.TextTestRunner(verbosity=2) # default=1 does not show success of unittests + runner = unittest.TextTestRunner(verbosity=2, # default=1 does not show success of unittests + resultclass=TBPLTextTestResult) unittest_results = runner.run(suite) results = TestResultCollection.from_unittest_results(None, unittest_results)