Bug 1017596 - Add suite_start and suite_end messages to moztest.adapters.unit. r=jgraham

This properly implements the structured logging protocol in the unittest
adapter.

The patch also adds an optional argument `test_list` to StructuredTestLogger
which will include an array of all tests when sending the suite_start message.
---
 testing/mozbase/moztest/moztest/adapters/unit.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

--HG--
extra : rebase_source : f8c9852485129bd034317c1b801a3f33a56162cf
This commit is contained in:
Andreas Tolfsen 2014-05-29 18:08:24 +01:00
parent 3fa2f7f3ec
commit c65ec71dc6

View File

@ -18,6 +18,7 @@ testsuites"""
class StructuredTestResult(TextTestResult):
def __init__(self, *args, **kwargs):
self.logger = kwargs.pop('logger')
self.test_list = kwargs.pop("test_list", [])
self.result_callbacks = kwargs.pop('result_callbacks', [])
self.passed = 0
self.testsRun = 0
@ -32,7 +33,7 @@ class StructuredTestResult(TextTestResult):
return debug_info
def startTestRun(self):
pass
self.logger.suite_start(tests=self.test_list)
def startTest(self, test):
self.testsRun += 1
@ -42,13 +43,13 @@ class StructuredTestResult(TextTestResult):
pass
def stopTestRun(self):
pass
self.logger.suite_end()
def addError(self, test, err):
self.errors.append((test, self._exc_info_to_string(err, test)))
extra = self.call_callbacks(test, "ERROR")
self.logger.test_end(test.id(),
"ERROR",
"ERROR",
message=self._exc_info_to_string(err, test),
expected="PASS",
extra=extra)
@ -95,9 +96,14 @@ class StructuredTestRunner(unittest.TextTestRunner):
def __init__(self, **kwargs):
"""TestRunner subclass designed for structured logging.
:params logger: a StructuredLogger to use for logging the test run.
:params logger: A ``StructuredLogger`` to use for logging the test run.
:params test_list: An optional list of tests that will be passed along
the `suite_start` message.
"""
self.logger = kwargs.pop("logger")
self.test_list = kwargs.pop("test_list", [])
self.result_callbacks = kwargs.pop("result_callbacks", [])
unittest.TextTestRunner.__init__(self, **kwargs)
@ -105,7 +111,8 @@ class StructuredTestRunner(unittest.TextTestRunner):
return self.resultclass(self.stream,
self.descriptions,
self.verbosity,
logger=self.logger)
logger=self.logger,
test_list=self.test_list)
def run(self, test):
"""Run the given test case or test suite."""