From 9c4be4fd58f405af4f90ce62a45d40c33e9e986e Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Mon, 20 Feb 2023 16:19:27 -0600 Subject: [PATCH 1/4] allow a progress bar even when capture=no --- src/_pytest/terminal.py | 14 ++++++++++---- testing/test_terminal.py | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 1b73da89bf4..a58c28a2fc6 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -229,7 +229,8 @@ def pytest_addoption(parser: Parser) -> None: parser.addini( "console_output_style", 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", ) @@ -346,14 +347,19 @@ def __init__(self, config: Config, file: Optional[TextIO] = None) -> None: def _determine_show_progress_info(self) -> "Literal['progress', 'count', False]": """Return whether we should display progress information based on the current config.""" - # do not show progress if we are not capturing output (#3038) - if self.config.getoption("capture", "no") == "no": + # do not show progress if we are not capturing output (#3038) unless explicitly + # 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 # do not show progress if we are showing fixture setup/teardown if self.config.getoption("setupshow", False): return False cfg: str = self.config.getini("console_output_style") - if cfg == "progress": + if cfg == "progress" or cfg == "progress-even-when-capture-no": return "progress" elif cfg == "count": return "count" diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 453f183236f..8a77e107d95 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -2213,6 +2213,24 @@ def test_capture_no(self, many_tests_files, pytester: Pytester) -> None: output = pytester.runpytest("--capture=no") 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: """Ensure we show the correct percentages for tests that fail during teardown (#3088)""" From 959afc6842843e731706f7365710863172d0348b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 Feb 2023 22:33:41 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/_pytest/terminal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index a58c28a2fc6..323c118e44b 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -230,7 +230,7 @@ def pytest_addoption(parser: Parser) -> None: "console_output_style", help='Console output: "classic", or with additional progress information ' '("progress" (percentage) | "count" | "progress-even-when-capture-no" (forces ' - 'progress even when capture=no)', + "progress even when capture=no)", default="progress", ) From 364d3dc2bd1f181f3cdbb4e53ab90f29cf72d3c5 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sun, 26 Feb 2023 13:20:30 +0800 Subject: [PATCH 3/4] add changelog and docs --- changelog/10755.improvement.rst | 1 + doc/en/reference/reference.rst | 1 + 2 files changed, 2 insertions(+) create mode 100644 changelog/10755.improvement.rst diff --git a/changelog/10755.improvement.rst b/changelog/10755.improvement.rst new file mode 100644 index 00000000000..7d0fa27b15c --- /dev/null +++ b/changelog/10755.improvement.rst @@ -0,0 +1 @@ +``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. diff --git a/doc/en/reference/reference.rst b/doc/en/reference/reference.rst index 288a4050dbb..0b9262c88bd 100644 --- a/doc/en/reference/reference.rst +++ b/doc/en/reference/reference.rst @@ -1212,6 +1212,7 @@ passed multiple times. The expected format is ``name=value``. For example:: * ``classic``: classic pytest output. * ``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. The default is ``progress``, but you can fallback to ``classic`` if you prefer or From db8ee7034169ed4834a462b02f5e13c82980b337 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 7 Mar 2023 17:26:42 -0300 Subject: [PATCH 4/4] Improve changelog a bit --- changelog/10755.feature.rst | 1 + changelog/10755.improvement.rst | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 changelog/10755.feature.rst delete mode 100644 changelog/10755.improvement.rst diff --git a/changelog/10755.feature.rst b/changelog/10755.feature.rst new file mode 100644 index 00000000000..5fb5a97d4ac --- /dev/null +++ b/changelog/10755.feature.rst @@ -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. diff --git a/changelog/10755.improvement.rst b/changelog/10755.improvement.rst deleted file mode 100644 index 7d0fa27b15c..00000000000 --- a/changelog/10755.improvement.rst +++ /dev/null @@ -1 +0,0 @@ -``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.