Add the progress_display_mode ini option

This commit is contained in:
Jeffrey Rackauckas 2018-08-23 22:56:25 -07:00
parent 067de257e1
commit 93f783228c
3 changed files with 54 additions and 4 deletions

View File

@ -0,0 +1 @@
Added the `progress_display_mode` ini option to enable displaying the progress as a count instead of a percentage.

View File

@ -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()

View File

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