mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1078869 - Structured logging for mozbase unit tests. r=ahal
This commit is contained in:
parent
1596679a9f
commit
c0bbc5e8b2
@ -582,7 +582,7 @@ class TestCommandline(unittest.TestCase):
|
||||
parser = argparse.ArgumentParser()
|
||||
commandline.add_logging_group(parser)
|
||||
args = parser.parse_args(["--log-raw=-"])
|
||||
logger = commandline.setup_logging("test", args, {})
|
||||
logger = commandline.setup_logging("test_setup_logging", args, {})
|
||||
self.assertEqual(len(logger.handlers), 1)
|
||||
|
||||
def test_setup_logging_optparse(self):
|
||||
|
@ -17,28 +17,12 @@ import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from mozlog import structured
|
||||
from moztest.results import TestResultCollection
|
||||
|
||||
from moztest.adapters.unit import StructuredTestRunner
|
||||
|
||||
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"""
|
||||
|
||||
@ -67,7 +51,13 @@ def main(args=sys.argv[1:]):
|
||||
parser.add_option('--list', dest='list_tests',
|
||||
action='store_true', default=False,
|
||||
help="list paths of tests to be run")
|
||||
structured.commandline.add_logging_group(parser)
|
||||
options, args = parser.parse_args(args)
|
||||
logger = structured.commandline.setup_logging("mozbase",
|
||||
options,
|
||||
{
|
||||
"tbpl": sys.stdout
|
||||
})
|
||||
|
||||
# read the manifest
|
||||
if args:
|
||||
@ -89,6 +79,8 @@ def main(args=sys.argv[1:]):
|
||||
# gather the tests
|
||||
tests = manifest.active_tests(disabled=False, **mozinfo.info)
|
||||
tests = [test['path'] for test in tests]
|
||||
logger.suite_start(tests)
|
||||
|
||||
if options.list_tests:
|
||||
# print test paths
|
||||
print '\n'.join(tests)
|
||||
@ -101,10 +93,10 @@ 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
|
||||
resultclass=TBPLTextTestResult)
|
||||
runner = StructuredTestRunner(logger=logger)
|
||||
unittest_results = runner.run(suite)
|
||||
results = TestResultCollection.from_unittest_results(None, unittest_results)
|
||||
logger.suite_end()
|
||||
|
||||
# exit according to results
|
||||
sys.exit(1 if results.num_failures else 0)
|
||||
|
Loading…
Reference in New Issue
Block a user