Fix verbosity bug in --collect-only (#5391)
Fix verbosity bug in --collect-only
This commit is contained in:
commit
3656885d0d
|
@ -0,0 +1,2 @@
|
||||||
|
``-q`` has again an impact on the style of the collected items
|
||||||
|
(``--collect-only``) when ``--log-cli-level`` is used.
|
|
@ -409,10 +409,6 @@ class LoggingPlugin:
|
||||||
"""
|
"""
|
||||||
self._config = config
|
self._config = config
|
||||||
|
|
||||||
# enable verbose output automatically if live logging is enabled
|
|
||||||
if self._log_cli_enabled() and config.getoption("verbose") < 1:
|
|
||||||
config.option.verbose = 1
|
|
||||||
|
|
||||||
self.print_logs = get_option_ini(config, "log_print")
|
self.print_logs = get_option_ini(config, "log_print")
|
||||||
self.formatter = self._create_formatter(
|
self.formatter = self._create_formatter(
|
||||||
get_option_ini(config, "log_format"),
|
get_option_ini(config, "log_format"),
|
||||||
|
@ -628,6 +624,15 @@ class LoggingPlugin:
|
||||||
@pytest.hookimpl(hookwrapper=True)
|
@pytest.hookimpl(hookwrapper=True)
|
||||||
def pytest_runtestloop(self, session):
|
def pytest_runtestloop(self, session):
|
||||||
"""Runs all collected test items."""
|
"""Runs all collected test items."""
|
||||||
|
|
||||||
|
if session.config.option.collectonly:
|
||||||
|
yield
|
||||||
|
return
|
||||||
|
|
||||||
|
if self._log_cli_enabled() and self._config.getoption("verbose") < 1:
|
||||||
|
# setting verbose flag is needed to avoid messy test progress output
|
||||||
|
self._config.option.verbose = 1
|
||||||
|
|
||||||
with self.live_logs_context():
|
with self.live_logs_context():
|
||||||
if self.log_file_handler is not None:
|
if self.log_file_handler is not None:
|
||||||
with catching_logs(self.log_file_handler, level=self.log_file_level):
|
with catching_logs(self.log_file_handler, level=self.log_file_level):
|
||||||
|
|
|
@ -916,13 +916,44 @@ def test_collection_live_logging(testdir):
|
||||||
|
|
||||||
result = testdir.runpytest("--log-cli-level=INFO")
|
result = testdir.runpytest("--log-cli-level=INFO")
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(
|
||||||
|
["*--- live log collection ---*", "*Normal message*", "collected 0 items"]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("verbose", ["", "-q", "-qq"])
|
||||||
|
def test_collection_collect_only_live_logging(testdir, verbose):
|
||||||
|
testdir.makepyfile(
|
||||||
|
"""
|
||||||
|
def test_simple():
|
||||||
|
pass
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
result = testdir.runpytest("--collect-only", "--log-cli-level=INFO", verbose)
|
||||||
|
|
||||||
|
expected_lines = []
|
||||||
|
|
||||||
|
if not verbose:
|
||||||
|
expected_lines.extend(
|
||||||
[
|
[
|
||||||
"collecting*",
|
"*collected 1 item*",
|
||||||
"*--- live log collection ---*",
|
"*<Module test_collection_collect_only_live_logging.py>*",
|
||||||
"*Normal message*",
|
"*no tests ran*",
|
||||||
"collected 0 items",
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
elif verbose == "-q":
|
||||||
|
assert "collected 1 item*" not in result.stdout.str()
|
||||||
|
expected_lines.extend(
|
||||||
|
[
|
||||||
|
"*test_collection_collect_only_live_logging.py::test_simple*",
|
||||||
|
"no tests ran in * seconds",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
elif verbose == "-qq":
|
||||||
|
assert "collected 1 item*" not in result.stdout.str()
|
||||||
|
expected_lines.extend(["*test_collection_collect_only_live_logging.py: 1*"])
|
||||||
|
|
||||||
|
result.stdout.fnmatch_lines(expected_lines)
|
||||||
|
|
||||||
|
|
||||||
def test_collection_logging_to_file(testdir):
|
def test_collection_logging_to_file(testdir):
|
||||||
|
|
Loading…
Reference in New Issue