Skip to content

Commit e865b27

Browse files
committed
Fix verbosity bug in --collect-only
1 parent 6a6b6d8 commit e865b27

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

changelog/5383.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``-q`` has again an impact on the style of the collected items
2+
(``--collect-only``) when ``--log-cli-level`` is used.

src/_pytest/logging.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,6 @@ def __init__(self, config):
409409
"""
410410
self._config = config
411411

412-
# enable verbose output automatically if live logging is enabled
413-
if self._log_cli_enabled() and config.getoption("verbose") < 1:
414-
config.option.verbose = 1
415-
416412
self.print_logs = get_option_ini(config, "log_print")
417413
self.formatter = self._create_formatter(
418414
get_option_ini(config, "log_format"),
@@ -628,6 +624,10 @@ def pytest_sessionstart(self):
628624
@pytest.hookimpl(hookwrapper=True)
629625
def pytest_runtestloop(self, session):
630626
"""Runs all collected test items."""
627+
if self._log_cli_enabled() and self._config.getoption("verbose") < 1:
628+
# setting verbose flag is needed to avoid messy test progress output
629+
self._config.option.verbose = 1
630+
631631
with self.live_logs_context():
632632
if self.log_file_handler is not None:
633633
with catching_logs(self.log_file_handler, level=self.log_file_level):

testing/logging/test_reporting.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -916,12 +916,7 @@ def test_collection_live_logging(testdir):
916916

917917
result = testdir.runpytest("--log-cli-level=INFO")
918918
result.stdout.fnmatch_lines(
919-
[
920-
"collecting*",
921-
"*--- live log collection ---*",
922-
"*Normal message*",
923-
"collected 0 items",
924-
]
919+
["*--- live log collection ---*", "*Normal message*", "collected 0 items"]
925920
)
926921

927922

0 commit comments

Comments
 (0)