@@ -338,7 +338,7 @@ def __init__(self, config):
338338 self ._config = config
339339
340340 # enable verbose output automatically if live logging is enabled
341- if self ._config . getini ( 'log_cli' ) and not config .getoption ('verbose' ):
341+ if self ._log_cli_enabled ( ) and not config .getoption ('verbose' ):
342342 # sanity check: terminal reporter should not have been loaded at this point
343343 assert self ._config .pluginmanager .get_plugin ('terminalreporter' ) is None
344344 config .option .verbose = 1
@@ -364,6 +364,13 @@ def __init__(self, config):
364364 # initialized during pytest_runtestloop
365365 self .log_cli_handler = None
366366
367+ def _log_cli_enabled (self ):
368+ """Return True if log_cli should be considered enabled, either explicitly
369+ or because --log-cli-level was given in the command-line.
370+ """
371+ return self ._config .getoption ('--log-cli-level' ) is not None or \
372+ self ._config .getini ('log_cli' )
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 ._log_cli_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