mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Bug 857984 - mach mochitest now colorizes and prints failure summary; r=Ms2ger
--HG-- extra : rebase_source : 97900c2bf0aaa83a3a9fa5e4dc88901140f66e60
This commit is contained in:
parent
24d10f8c80
commit
5d06e0201d
@ -61,12 +61,16 @@ class StructuredHumanFormatter(logging.Formatter):
|
||||
Because of this limitation, format() will fail with a KeyError if an
|
||||
unstructured record is passed or if the structured message is malformed.
|
||||
"""
|
||||
def __init__(self, start_time, write_interval=False):
|
||||
def __init__(self, start_time, write_interval=False, write_times=True):
|
||||
self.start_time = start_time
|
||||
self.write_interval = write_interval
|
||||
self.write_times = write_times
|
||||
self.last_time = None
|
||||
|
||||
def format(self, record):
|
||||
if not self.write_times:
|
||||
return record.msg.format(**record.params)
|
||||
|
||||
elapsed = self._time(record)
|
||||
|
||||
return '%s %s' % (format_seconds(elapsed),
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
import mozpack.path
|
||||
import os
|
||||
import platform
|
||||
@ -20,6 +21,14 @@ from mach.decorators import (
|
||||
Command,
|
||||
)
|
||||
|
||||
from mach.logging import StructuredHumanFormatter
|
||||
|
||||
|
||||
class UnexpectedFilter(logging.Filter):
|
||||
def filter(self, record):
|
||||
return 'TEST-UNEXPECTED-' in record.message
|
||||
|
||||
|
||||
|
||||
class MochitestRunner(MozbuildObject):
|
||||
"""Easily run mochitests.
|
||||
@ -70,6 +79,7 @@ class MochitestRunner(MozbuildObject):
|
||||
print('No failure file present. Did you run mochitests before?')
|
||||
return 1
|
||||
|
||||
from StringIO import StringIO
|
||||
from automation import Automation
|
||||
|
||||
# runtests.py is ambiguous, so we load the file/module manually.
|
||||
@ -144,7 +154,28 @@ class MochitestRunner(MozbuildObject):
|
||||
if debugger:
|
||||
options.debugger = debugger
|
||||
|
||||
return runner.runTests(options)
|
||||
# We need this to enable colorization of output.
|
||||
self.log_manager.enable_unstructured()
|
||||
|
||||
# Output processing is a little funky here. The old make targets
|
||||
# grepped the log output from TEST-UNEXPECTED-* and printed these lines
|
||||
# after test execution. Ideally the test runner would expose a Python
|
||||
# API for obtaining test results and we could just format failures
|
||||
# appropriately. Unfortunately, it doesn't yet do that. So, we capture
|
||||
# all output to a buffer then "grep" the buffer after test execution.
|
||||
# Bug 858197 tracks a Python API that would facilitate this.
|
||||
test_output = StringIO()
|
||||
handler = logging.StreamHandler(test_output)
|
||||
handler.addFilter(UnexpectedFilter())
|
||||
handler.setFormatter(StructuredHumanFormatter(0, write_times=False))
|
||||
logging.getLogger().addHandler(handler)
|
||||
|
||||
result = runner.runTests(options)
|
||||
|
||||
if test_output.getvalue():
|
||||
print(test_output.getvalue())
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def MochitestCommand(func):
|
||||
|
Loading…
Reference in New Issue
Block a user