New option to allow a progress report even when capture=no (#10755)
This commit is contained in:
parent
5e98aefc92
commit
a869141b3d
|
@ -0,0 +1 @@
|
||||||
|
:confval:`console_output_style` now supports ``progress-even-when-capture-no`` to force the use of the progress output even when capture is disabled. This is useful in large test suites where capture may have significant performance impact.
|
|
@ -1220,6 +1220,7 @@ passed multiple times. The expected format is ``name=value``. For example::
|
||||||
|
|
||||||
* ``classic``: classic pytest output.
|
* ``classic``: classic pytest output.
|
||||||
* ``progress``: like classic pytest output, but with a progress indicator.
|
* ``progress``: like classic pytest output, but with a progress indicator.
|
||||||
|
* ``progress-even-when-capture-no``: allows the use of the progress indicator even when ``capture=no``.
|
||||||
* ``count``: like progress, but shows progress as the number of tests completed instead of a percent.
|
* ``count``: like progress, but shows progress as the number of tests completed instead of a percent.
|
||||||
|
|
||||||
The default is ``progress``, but you can fallback to ``classic`` if you prefer or
|
The default is ``progress``, but you can fallback to ``classic`` if you prefer or
|
||||||
|
|
|
@ -229,7 +229,8 @@ def pytest_addoption(parser: Parser) -> None:
|
||||||
parser.addini(
|
parser.addini(
|
||||||
"console_output_style",
|
"console_output_style",
|
||||||
help='Console output: "classic", or with additional progress information '
|
help='Console output: "classic", or with additional progress information '
|
||||||
'("progress" (percentage) | "count")',
|
'("progress" (percentage) | "count" | "progress-even-when-capture-no" (forces '
|
||||||
|
"progress even when capture=no)",
|
||||||
default="progress",
|
default="progress",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -346,14 +347,19 @@ class TerminalReporter:
|
||||||
|
|
||||||
def _determine_show_progress_info(self) -> "Literal['progress', 'count', False]":
|
def _determine_show_progress_info(self) -> "Literal['progress', 'count', False]":
|
||||||
"""Return whether we should display progress information based on the current config."""
|
"""Return whether we should display progress information based on the current config."""
|
||||||
# do not show progress if we are not capturing output (#3038)
|
# do not show progress if we are not capturing output (#3038) unless explicitly
|
||||||
if self.config.getoption("capture", "no") == "no":
|
# overridden by progress-even-when-capture-no
|
||||||
|
if (
|
||||||
|
self.config.getoption("capture", "no") == "no"
|
||||||
|
and self.config.getini("console_output_style")
|
||||||
|
!= "progress-even-when-capture-no"
|
||||||
|
):
|
||||||
return False
|
return False
|
||||||
# do not show progress if we are showing fixture setup/teardown
|
# do not show progress if we are showing fixture setup/teardown
|
||||||
if self.config.getoption("setupshow", False):
|
if self.config.getoption("setupshow", False):
|
||||||
return False
|
return False
|
||||||
cfg: str = self.config.getini("console_output_style")
|
cfg: str = self.config.getini("console_output_style")
|
||||||
if cfg == "progress":
|
if cfg == "progress" or cfg == "progress-even-when-capture-no":
|
||||||
return "progress"
|
return "progress"
|
||||||
elif cfg == "count":
|
elif cfg == "count":
|
||||||
return "count"
|
return "count"
|
||||||
|
|
|
@ -2213,6 +2213,24 @@ class TestProgressOutputStyle:
|
||||||
output = pytester.runpytest("--capture=no")
|
output = pytester.runpytest("--capture=no")
|
||||||
output.stdout.no_fnmatch_line("*%]*")
|
output.stdout.no_fnmatch_line("*%]*")
|
||||||
|
|
||||||
|
def test_capture_no_progress_enabled(
|
||||||
|
self, many_tests_files, pytester: Pytester
|
||||||
|
) -> None:
|
||||||
|
pytester.makeini(
|
||||||
|
"""
|
||||||
|
[pytest]
|
||||||
|
console_output_style = progress-even-when-capture-no
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
output = pytester.runpytest("-s")
|
||||||
|
output.stdout.re_match_lines(
|
||||||
|
[
|
||||||
|
r"test_bar.py \.{10} \s+ \[ 50%\]",
|
||||||
|
r"test_foo.py \.{5} \s+ \[ 75%\]",
|
||||||
|
r"test_foobar.py \.{5} \s+ \[100%\]",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestProgressWithTeardown:
|
class TestProgressWithTeardown:
|
||||||
"""Ensure we show the correct percentages for tests that fail during teardown (#3088)"""
|
"""Ensure we show the correct percentages for tests that fail during teardown (#3088)"""
|
||||||
|
|
Loading…
Reference in New Issue