From 93f783228c3dfebd77a53e1d2e5fa81b49ae107a Mon Sep 17 00:00:00 2001 From: Jeffrey Rackauckas Date: Thu, 23 Aug 2018 22:56:25 -0700 Subject: [PATCH 1/9] 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") From 5fefc48f3332c7143d6f1ce5d4e70dc933100319 Mon Sep 17 00:00:00 2001 From: Jeffrey Rackauckas Date: Thu, 23 Aug 2018 23:00:02 -0700 Subject: [PATCH 2/9] Fixing pre-commit hooks --- testing/test_terminal.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index b102d1c33..64d909772 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1148,7 +1148,8 @@ class TestProgress(object): """ [pytest] progress_display_mode = count - """) + """ + ) output = testdir.runpytest() output.stdout.re_match_lines( [ @@ -1173,7 +1174,8 @@ class TestProgress(object): """ [pytest] progress_display_mode = count - """) + """ + ) output = testdir.runpytest("-v") output.stdout.re_match_lines( [ @@ -1188,7 +1190,7 @@ class TestProgress(object): output = testdir.runpytest("-n2") output.stdout.re_match_lines([r"\.{20} \s+ \[100%\]"]) - def test_xdist_normal(self, many_tests_files, testdir): + def test_xdist_normal_count(self, many_tests_files, testdir): pytest.importorskip("xdist") output = testdir.runpytest("-n2") output.stdout.re_match_lines([r"\.{20} \s+ \[ 20 / 20 \]"]) From 5e260c4d3442505c8b3cbe2fc9e8571f872e7310 Mon Sep 17 00:00:00 2001 From: Jeffrey Rackauckas Date: Sat, 25 Aug 2018 21:50:19 -0700 Subject: [PATCH 3/9] Fixing changelog file. --- changelog/3829.feature.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/3829.feature.rst b/changelog/3829.feature.rst index 3d9b64365..06354e0c8 100644 --- a/changelog/3829.feature.rst +++ b/changelog/3829.feature.rst @@ -1 +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 +Added the `progress_display_mode` ini option to enable displaying the progress as a count instead of a percentage. From dda5e5ea328db9b80dbb098a925f2117c486010a Mon Sep 17 00:00:00 2001 From: Jeffrey Rackauckas Date: Sat, 25 Aug 2018 21:55:00 -0700 Subject: [PATCH 4/9] Fixing backticks in changelog file. --- changelog/3829.feature.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/3829.feature.rst b/changelog/3829.feature.rst index 06354e0c8..a6a24c47b 100644 --- a/changelog/3829.feature.rst +++ b/changelog/3829.feature.rst @@ -1 +1 @@ -Added the `progress_display_mode` ini option to enable displaying the progress as a count instead of a percentage. +Added the ``progress_display_mode`` ini option to enable displaying the progress as a count instead of a percentage. From 325319dc3b27febe63b6e2ea59bf6e4923207529 Mon Sep 17 00:00:00 2001 From: Jeffrey Rackauckas Date: Sat, 25 Aug 2018 22:18:29 -0700 Subject: [PATCH 5/9] Fixing xdist test to properly configure an ini file. --- testing/test_terminal.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 64d909772..c0240c58f 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1188,10 +1188,17 @@ class TestProgress(object): def test_xdist_normal(self, many_tests_files, testdir): pytest.importorskip("xdist") output = testdir.runpytest("-n2") + sys.stderr.write(output.stdout) output.stdout.re_match_lines([r"\.{20} \s+ \[100%\]"]) def test_xdist_normal_count(self, many_tests_files, testdir): pytest.importorskip("xdist") + testdir.makeini( + """ + [pytest] + progress_display_mode = count + """ + ) output = testdir.runpytest("-n2") output.stdout.re_match_lines([r"\.{20} \s+ \[ 20 / 20 \]"]) From 2a917a582ed21e679e310dc37b964439d2ee7bad Mon Sep 17 00:00:00 2001 From: Jeffrey Rackauckas Date: Sat, 25 Aug 2018 22:21:50 -0700 Subject: [PATCH 6/9] Removing accidental change to test --- testing/test_terminal.py | 1 - 1 file changed, 1 deletion(-) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index c0240c58f..5ab82444a 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1188,7 +1188,6 @@ class TestProgress(object): def test_xdist_normal(self, many_tests_files, testdir): pytest.importorskip("xdist") output = testdir.runpytest("-n2") - sys.stderr.write(output.stdout) output.stdout.re_match_lines([r"\.{20} \s+ \[100%\]"]) def test_xdist_normal_count(self, many_tests_files, testdir): From 8f4685e02479c051db62ee2cf00c074b5e7ce026 Mon Sep 17 00:00:00 2001 From: Jeffrey Rackauckas Date: Sun, 26 Aug 2018 19:21:00 -0700 Subject: [PATCH 7/9] Move count display style to be part of console_output_style, fixed test progress for count console output style. --- doc/en/reference.rst | 2 +- src/_pytest/terminal.py | 21 +++++++++++++++------ testing/test_terminal.py | 6 +++--- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/doc/en/reference.rst b/doc/en/reference.rst index fe9e87042..65953e52f 100644 --- a/doc/en/reference.rst +++ b/doc/en/reference.rst @@ -916,7 +916,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. - + * ``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 new mode is causing unexpected problems: diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 480a81f6e..056ab01a8 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -260,7 +260,10 @@ class TerminalReporter(object): # do not show progress if we are showing fixture setup/teardown if self.config.getoption("setupshow"): return False - return self.config.getini("console_output_style") == "progress" + return ( + self.config.getini("console_output_style") == "progress" + or self.config.getini("console_output_style") == "count" + ) def hasopt(self, char): char = {"xfailed": "x", "skipped": "s"}.get(char, char) @@ -410,6 +413,14 @@ class TerminalReporter(object): self.currentfspath = -2 def pytest_runtest_logfinish(self, nodeid): + if self.config.getini("console_output_style") == "count": + num_tests = self._session.testscollected + _PROGRESS_LENGTH = len( + " [ {} / {} ]".format(str(num_tests), str(num_tests)) + ) + else: + _PROGRESS_LENGTH = len(" [100%]") + if self.verbosity <= 0 and self._show_progress_info: self._progress_nodeids_reported.add(nodeid) last_item = ( @@ -419,24 +430,22 @@ class TerminalReporter(object): self._write_progress_information_filling_space() else: past_edge = ( - self._tw.chars_on_current_line + self._PROGRESS_LENGTH + 1 + self._tw.chars_on_current_line + _PROGRESS_LENGTH + 1 >= self._screen_width ) if past_edge: msg = self._get_progress_information_message() self._tw.write(msg + "\n", cyan=True) - _PROGRESS_LENGTH = len(" [100%]") - def _get_progress_information_message(self): if self.config.getoption("capture") == "no": return "" collected = self._session.testscollected - if self.config.getini("progress_display_mode") == "count": + if self.config.getini("console_output_style") == "count": if collected: progress = self._progress_nodeids_reported counter_format = "{{:{}d}}".format(len(str(collected))) - format_string = "[ {} / {{}} ]".format(counter_format) + format_string = " [ {} / {{}} ]".format(counter_format) return format_string.format(len(progress), collected) return " [ {} / {} ]".format(collected, collected) else: diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 5ab82444a..0ce357b68 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1147,7 +1147,7 @@ class TestProgress(object): testdir.makeini( """ [pytest] - progress_display_mode = count + console_output_style = count """ ) output = testdir.runpytest() @@ -1173,7 +1173,7 @@ class TestProgress(object): testdir.makeini( """ [pytest] - progress_display_mode = count + console_output_style = count """ ) output = testdir.runpytest("-v") @@ -1195,7 +1195,7 @@ class TestProgress(object): testdir.makeini( """ [pytest] - progress_display_mode = count + console_output_style = count """ ) output = testdir.runpytest("-n2") From 23295e1e987cdf5c926e94d75b55dada945d65be Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 27 Aug 2018 20:21:08 -0300 Subject: [PATCH 8/9] Fix docs linting --- doc/en/reference.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/en/reference.rst b/doc/en/reference.rst index 65953e52f..9b0c0bc71 100644 --- a/doc/en/reference.rst +++ b/doc/en/reference.rst @@ -917,6 +917,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. * ``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 new mode is causing unexpected problems: From 4b94760c8e32400cce807eef132e40499e871a50 Mon Sep 17 00:00:00 2001 From: Jeffrey Rackauckas Date: Mon, 27 Aug 2018 20:23:17 -0700 Subject: [PATCH 9/9] Removed spacing in count display. --- changelog/3829.feature.rst | 2 +- src/_pytest/terminal.py | 21 +++++---------------- testing/test_terminal.py | 14 +++++++------- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/changelog/3829.feature.rst b/changelog/3829.feature.rst index a6a24c47b..d3bfdb8e6 100644 --- a/changelog/3829.feature.rst +++ b/changelog/3829.feature.rst @@ -1 +1 @@ -Added the ``progress_display_mode`` ini option to enable displaying the progress as a count instead of a percentage. +Added the ``count`` option to ``console_output_style`` to enable displaying the progress as a count instead of a percentage. diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 056ab01a8..1251b1479 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -143,12 +143,6 @@ 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) @@ -260,10 +254,7 @@ class TerminalReporter(object): # do not show progress if we are showing fixture setup/teardown if self.config.getoption("setupshow"): return False - return ( - self.config.getini("console_output_style") == "progress" - or self.config.getini("console_output_style") == "count" - ) + return self.config.getini("console_output_style") in ("progress", "count") def hasopt(self, char): char = {"xfailed": "x", "skipped": "s"}.get(char, char) @@ -415,11 +406,9 @@ class TerminalReporter(object): def pytest_runtest_logfinish(self, nodeid): if self.config.getini("console_output_style") == "count": num_tests = self._session.testscollected - _PROGRESS_LENGTH = len( - " [ {} / {} ]".format(str(num_tests), str(num_tests)) - ) + progress_length = len(" [{}/{}]".format(str(num_tests), str(num_tests))) else: - _PROGRESS_LENGTH = len(" [100%]") + progress_length = len(" [100%]") if self.verbosity <= 0 and self._show_progress_info: self._progress_nodeids_reported.add(nodeid) @@ -430,7 +419,7 @@ class TerminalReporter(object): self._write_progress_information_filling_space() else: past_edge = ( - self._tw.chars_on_current_line + _PROGRESS_LENGTH + 1 + self._tw.chars_on_current_line + progress_length + 1 >= self._screen_width ) if past_edge: @@ -445,7 +434,7 @@ class TerminalReporter(object): if collected: progress = self._progress_nodeids_reported counter_format = "{{:{}d}}".format(len(str(collected))) - format_string = " [ {} / {{}} ]".format(counter_format) + format_string = " [{}/{{}}]".format(counter_format) return format_string.format(len(progress), collected) return " [ {} / {} ]".format(collected, collected) else: diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 0ce357b68..1a1d20c95 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1153,9 +1153,9 @@ class TestProgress(object): 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 \]", + r"test_bar.py \.{10} \s+ \[10/20\]", + r"test_foo.py \.{5} \s+ \[15/20\]", + r"test_foobar.py \.{5} \s+ \[20/20\]", ] ) @@ -1179,9 +1179,9 @@ class TestProgress(object): 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 \]", + 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\]", ] ) @@ -1199,7 +1199,7 @@ class TestProgress(object): """ ) output = testdir.runpytest("-n2") - output.stdout.re_match_lines([r"\.{20} \s+ \[ 20 / 20 \]"]) + output.stdout.re_match_lines([r"\.{20} \s+ \[20/20\]"]) def test_xdist_verbose(self, many_tests_files, testdir): pytest.importorskip("xdist")