@@ -336,9 +336,10 @@ def __init__(self, config):
336336 create a single one for the entire test session here.
337337 """
338338 self ._config = config
339+ self ._stream_logs = None
339340
340341 # enable verbose output automatically if live logging is enabled
341- if self ._config . getini ( 'log_cli' ) and not config .getoption ('verbose' ):
342+ if self ._stream_logs_enabled ( ) and not config .getoption ('verbose' ):
342343 # sanity check: terminal reporter should not have been loaded at this point
343344 assert self ._config .pluginmanager .get_plugin ('terminalreporter' ) is None
344345 config .option .verbose = 1
@@ -364,6 +365,12 @@ def __init__(self, config):
364365 # initialized during pytest_runtestloop
365366 self .log_cli_handler = None
366367
368+ def _stream_logs_enabled (self ):
369+ if self ._stream_logs is None :
370+ self ._stream_logs = self ._config .getoption ('--log-cli-level' ) is not None or \
371+ self ._config .getini ('log_cli' )
372+ return self ._stream_logs
373+
367374 @contextmanager
368375 def _runtest_for (self , item , when ):
369376 """Implements the internals of pytest_runtest_xxx() hook."""
@@ -438,7 +445,7 @@ def _setup_cli_logging(self):
438445 This must be done right before starting the loop so we can access the terminal reporter plugin.
439446 """
440447 terminal_reporter = self ._config .pluginmanager .get_plugin ('terminalreporter' )
441- if self ._config . getini ( 'log_cli' ) and terminal_reporter is not None :
448+ if self ._stream_logs_enabled ( ) and terminal_reporter is not None :
442449 capture_manager = self ._config .pluginmanager .get_plugin ('capturemanager' )
443450 log_cli_handler = _LiveLoggingStreamHandler (terminal_reporter , capture_manager )
444451 log_cli_format = get_option_ini (self ._config , 'log_cli_format' , 'log_format' )
0 commit comments