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")