Add the progress_display_mode ini option
This commit is contained in:
parent
067de257e1
commit
93f783228c
|
@ -0,0 +1 @@
|
||||||
|
Added the `progress_display_mode` ini option to enable displaying the progress as a count instead of a percentage.
|
|
@ -143,6 +143,12 @@ def pytest_addoption(parser):
|
||||||
default="progress",
|
default="progress",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.addini(
|
||||||
|
"progress_display_mode",
|
||||||
|
help="Controls how to show the test progress (percentage|count)",
|
||||||
|
default="percentage",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def pytest_configure(config):
|
def pytest_configure(config):
|
||||||
reporter = TerminalReporter(config, sys.stdout)
|
reporter = TerminalReporter(config, sys.stdout)
|
||||||
|
@ -426,10 +432,18 @@ class TerminalReporter(object):
|
||||||
if self.config.getoption("capture") == "no":
|
if self.config.getoption("capture") == "no":
|
||||||
return ""
|
return ""
|
||||||
collected = self._session.testscollected
|
collected = self._session.testscollected
|
||||||
if collected:
|
if self.config.getini("progress_display_mode") == "count":
|
||||||
progress = len(self._progress_nodeids_reported) * 100 // collected
|
if collected:
|
||||||
return " [{:3d}%]".format(progress)
|
progress = self._progress_nodeids_reported
|
||||||
return " [100%]"
|
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):
|
def _write_progress_information_filling_space(self):
|
||||||
msg = self._get_progress_information_message()
|
msg = self._get_progress_information_message()
|
||||||
|
|
|
@ -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):
|
def test_verbose(self, many_tests_files, testdir):
|
||||||
output = testdir.runpytest("-v")
|
output = testdir.runpytest("-v")
|
||||||
output.stdout.re_match_lines(
|
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):
|
def test_xdist_normal(self, many_tests_files, testdir):
|
||||||
pytest.importorskip("xdist")
|
pytest.importorskip("xdist")
|
||||||
output = testdir.runpytest("-n2")
|
output = testdir.runpytest("-n2")
|
||||||
output.stdout.re_match_lines([r"\.{20} \s+ \[100%\]"])
|
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):
|
def test_xdist_verbose(self, many_tests_files, testdir):
|
||||||
pytest.importorskip("xdist")
|
pytest.importorskip("xdist")
|
||||||
output = testdir.runpytest("-n2", "-v")
|
output = testdir.runpytest("-n2", "-v")
|
||||||
|
|
Loading…
Reference in New Issue