Skip to content

Commit a869141

Browse files
authored
New option to allow a progress report even when capture=no (#10755)
1 parent 5e98aef commit a869141

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

changelog/10755.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

doc/en/reference/reference.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,7 @@ passed multiple times. The expected format is ``name=value``. For example::
12201220

12211221
* ``classic``: classic pytest output.
12221222
* ``progress``: like classic pytest output, but with a progress indicator.
1223+
* ``progress-even-when-capture-no``: allows the use of the progress indicator even when ``capture=no``.
12231224
* ``count``: like progress, but shows progress as the number of tests completed instead of a percent.
12241225

12251226
The default is ``progress``, but you can fallback to ``classic`` if you prefer or

src/_pytest/terminal.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ def pytest_addoption(parser: Parser) -> None:
229229
parser.addini(
230230
"console_output_style",
231231
help='Console output: "classic", or with additional progress information '
232-
'("progress" (percentage) | "count")',
232+
'("progress" (percentage) | "count" | "progress-even-when-capture-no" (forces '
233+
"progress even when capture=no)",
233234
default="progress",
234235
)
235236

@@ -346,14 +347,19 @@ def __init__(self, config: Config, file: Optional[TextIO] = None) -> None:
346347

347348
def _determine_show_progress_info(self) -> "Literal['progress', 'count', False]":
348349
"""Return whether we should display progress information based on the current config."""
349-
# do not show progress if we are not capturing output (#3038)
350-
if self.config.getoption("capture", "no") == "no":
350+
# do not show progress if we are not capturing output (#3038) unless explicitly
351+
# overridden by progress-even-when-capture-no
352+
if (
353+
self.config.getoption("capture", "no") == "no"
354+
and self.config.getini("console_output_style")
355+
!= "progress-even-when-capture-no"
356+
):
351357
return False
352358
# do not show progress if we are showing fixture setup/teardown
353359
if self.config.getoption("setupshow", False):
354360
return False
355361
cfg: str = self.config.getini("console_output_style")
356-
if cfg == "progress":
362+
if cfg == "progress" or cfg == "progress-even-when-capture-no":
357363
return "progress"
358364
elif cfg == "count":
359365
return "count"

testing/test_terminal.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,6 +2213,24 @@ def test_capture_no(self, many_tests_files, pytester: Pytester) -> None:
22132213
output = pytester.runpytest("--capture=no")
22142214
output.stdout.no_fnmatch_line("*%]*")
22152215

2216+
def test_capture_no_progress_enabled(
2217+
self, many_tests_files, pytester: Pytester
2218+
) -> None:
2219+
pytester.makeini(
2220+
"""
2221+
[pytest]
2222+
console_output_style = progress-even-when-capture-no
2223+
"""
2224+
)
2225+
output = pytester.runpytest("-s")
2226+
output.stdout.re_match_lines(
2227+
[
2228+
r"test_bar.py \.{10} \s+ \[ 50%\]",
2229+
r"test_foo.py \.{5} \s+ \[ 75%\]",
2230+
r"test_foobar.py \.{5} \s+ \[100%\]",
2231+
]
2232+
)
2233+
22162234

22172235
class TestProgressWithTeardown:
22182236
"""Ensure we show the correct percentages for tests that fail during teardown (#3088)"""

0 commit comments

Comments
 (0)