From 4b94760c8e32400cce807eef132e40499e871a50 Mon Sep 17 00:00:00 2001 From: Jeffrey Rackauckas Date: Mon, 27 Aug 2018 20:23:17 -0700 Subject: [PATCH] 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")