From 93f783228c3dfebd77a53e1d2e5fa81b49ae107a Mon Sep 17 00:00:00 2001 From: Jeffrey Rackauckas Date: Thu, 23 Aug 2018 22:56:25 -0700 Subject: [PATCH] Add the progress_display_mode ini option --- changelog/3829.feature.rst | 1 + src/_pytest/terminal.py | 22 ++++++++++++++++++---- testing/test_terminal.py | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 changelog/3829.feature.rst diff --git a/changelog/3829.feature.rst b/changelog/3829.feature.rst new file mode 100644 index 000000000..3d9b64365 --- /dev/null +++ b/changelog/3829.feature.rst @@ -0,0 +1 @@ +Added the `progress_display_mode` ini option to enable displaying the progress as a count instead of a percentage. \ No newline at end of file diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 7dd2edd6f..480a81f6e 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -143,6 +143,12 @@ def pytest_addoption(parser): default="progress", ) + parser.addini( + "progress_display_mode", + help="Controls how to show the test progress (percentage|count)", + default="percentage", + ) + def pytest_configure(config): reporter = TerminalReporter(config, sys.stdout) @@ -426,10 +432,18 @@ class TerminalReporter(object): if self.config.getoption("capture") == "no": return "" collected = self._session.testscollected - if collected: - progress = len(self._progress_nodeids_reported) * 100 // collected - return " [{:3d}%]".format(progress) - return " [100%]" + if self.config.getini("progress_display_mode") == "count": + if collected: + progress = self._progress_nodeids_reported + counter_format = "{{:{}d}}".format(len(str(collected))) + format_string = "[ {} / {{}} ]".format(counter_format) + return format_string.format(len(progress), collected) + return " [ {} / {} ]".format(collected, collected) + else: + if collected: + progress = len(self._progress_nodeids_reported) * 100 // collected + return " [{:3d}%]".format(progress) + return " [100%]" def _write_progress_information_filling_space(self): msg = self._get_progress_information_message() diff --git a/testing/test_terminal.py b/testing/test_terminal.py index a9da27980..b102d1c33 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1143,6 +1143,21 @@ class TestProgress(object): ] ) + def test_count(self, many_tests_files, testdir): + testdir.makeini( + """ + [pytest] + progress_display_mode = count + """) + output = testdir.runpytest() + output.stdout.re_match_lines( + [ + r"test_bar.py \.{10} \s+ \[ 10 / 20 \]", + r"test_foo.py \.{5} \s+ \[ 15 / 20 \]", + r"test_foobar.py \.{5} \s+ \[ 20 / 20 \]", + ] + ) + def test_verbose(self, many_tests_files, testdir): output = testdir.runpytest("-v") output.stdout.re_match_lines( @@ -1153,11 +1168,31 @@ class TestProgress(object): ] ) + def test_verbose_count(self, many_tests_files, testdir): + testdir.makeini( + """ + [pytest] + progress_display_mode = count + """) + output = testdir.runpytest("-v") + output.stdout.re_match_lines( + [ + r"test_bar.py::test_bar\[0\] PASSED \s+ \[ 1 / 20 \]", + r"test_foo.py::test_foo\[4\] PASSED \s+ \[ 15 / 20 \]", + r"test_foobar.py::test_foobar\[4\] PASSED \s+ \[ 20 / 20 \]", + ] + ) + def test_xdist_normal(self, many_tests_files, testdir): pytest.importorskip("xdist") output = testdir.runpytest("-n2") output.stdout.re_match_lines([r"\.{20} \s+ \[100%\]"]) + def test_xdist_normal(self, many_tests_files, testdir): + pytest.importorskip("xdist") + output = testdir.runpytest("-n2") + output.stdout.re_match_lines([r"\.{20} \s+ \[ 20 / 20 \]"]) + def test_xdist_verbose(self, many_tests_files, testdir): pytest.importorskip("xdist") output = testdir.runpytest("-n2", "-v")