bdd: Turn off colors with --color=no

This commit is contained in:
Florian Bruhin 2016-06-06 23:19:14 +02:00
parent b0df87842e
commit a9f27e3247

View File

@ -136,6 +136,7 @@ class QuteProc(testprocess.Process):
_profile: If True, do profiling of the subprocesses. _profile: If True, do profiling of the subprocesses.
_instance_id: An unique ID for this QuteProc instance _instance_id: An unique ID for this QuteProc instance
_run_counter: A counter to get an unique ID for each run. _run_counter: A counter to get an unique ID for each run.
_config: The pytest config object
Signals: Signals:
got_error: Emitted when there was an error log line. got_error: Emitted when there was an error log line.
@ -146,7 +147,8 @@ class QuteProc(testprocess.Process):
KEYS = ['timestamp', 'loglevel', 'category', 'module', 'function', 'line', KEYS = ['timestamp', 'loglevel', 'category', 'module', 'function', 'line',
'message'] 'message']
def __init__(self, httpbin, delay, *, profile=False, parent=None): def __init__(self, httpbin, delay, *, profile=False, config=None,
parent=None):
super().__init__(parent) super().__init__(parent)
self._profile = profile self._profile = profile
self._delay = delay self._delay = delay
@ -157,6 +159,7 @@ class QuteProc(testprocess.Process):
self._load_ready = False self._load_ready = False
self._instance_id = next(instance_counter) self._instance_id = next(instance_counter)
self._run_counter = itertools.count() self._run_counter = itertools.count()
self._config = config
def _is_ready(self, what): def _is_ready(self, what):
"""Called by _parse_line if loading/focusing is done. """Called by _parse_line if loading/focusing is done.
@ -183,8 +186,11 @@ class QuteProc(testprocess.Process):
else: else:
raise raise
colored_line = log_line.formatted_str() if self._config.getoption('--color') != 'no':
self._log(colored_line) line_to_log = log_line.formatted_str()
else:
line_to_log = log_line.formatted_str(colorized=False)
self._log(line_to_log)
start_okay_message_load = ( start_okay_message_load = (
"load status for <qutebrowser.browser.webview.WebView tab_id=0 " "load status for <qutebrowser.browser.webview.WebView tab_id=0 "
@ -554,7 +560,7 @@ def quteproc_process(qapp, httpbin, request):
"""Fixture for qutebrowser process which is started once per file.""" """Fixture for qutebrowser process which is started once per file."""
delay = request.config.getoption('--qute-delay') delay = request.config.getoption('--qute-delay')
profile = request.config.getoption('--qute-profile-subprocs') profile = request.config.getoption('--qute-profile-subprocs')
proc = QuteProc(httpbin, delay, profile=profile) proc = QuteProc(httpbin, delay, profile=profile, config=request.config)
proc.start() proc.start()
yield proc yield proc
proc.terminate() proc.terminate()
@ -574,7 +580,7 @@ def quteproc_new(qapp, httpbin, request):
"""Per-test qutebrowser process to test invocations.""" """Per-test qutebrowser process to test invocations."""
delay = request.config.getoption('--qute-delay') delay = request.config.getoption('--qute-delay')
profile = request.config.getoption('--qute-profile-subprocs') profile = request.config.getoption('--qute-profile-subprocs')
proc = QuteProc(httpbin, delay, profile=profile) proc = QuteProc(httpbin, delay, profile=profile, config=request.config)
request.node._quteproc_log = proc.captured_log request.node._quteproc_log = proc.captured_log
# Not calling before_test here as that would start the process # Not calling before_test here as that would start the process
yield proc yield proc