Fix count of selected tests on terminal collection summary (#9628)
This commit is contained in:
parent
f22451717d
commit
c9cf2d4424
|
@ -0,0 +1,3 @@
|
||||||
|
Fixed count of selected tests on terminal collection summary when there were errors or skipped modules.
|
||||||
|
|
||||||
|
If there were errors or skipped modules on collection, pytest would mistakenly subtract those from the selected count.
|
|
@ -663,7 +663,7 @@ class TerminalReporter:
|
||||||
errors = len(self.stats.get("error", []))
|
errors = len(self.stats.get("error", []))
|
||||||
skipped = len(self.stats.get("skipped", []))
|
skipped = len(self.stats.get("skipped", []))
|
||||||
deselected = len(self.stats.get("deselected", []))
|
deselected = len(self.stats.get("deselected", []))
|
||||||
selected = self._numcollected - errors - skipped - deselected
|
selected = self._numcollected - deselected
|
||||||
line = "collected " if final else "collecting "
|
line = "collected " if final else "collecting "
|
||||||
line += (
|
line += (
|
||||||
str(self._numcollected) + " item" + ("" if self._numcollected == 1 else "s")
|
str(self._numcollected) + " item" + ("" if self._numcollected == 1 else "s")
|
||||||
|
@ -674,7 +674,7 @@ class TerminalReporter:
|
||||||
line += " / %d deselected" % deselected
|
line += " / %d deselected" % deselected
|
||||||
if skipped:
|
if skipped:
|
||||||
line += " / %d skipped" % skipped
|
line += " / %d skipped" % skipped
|
||||||
if self._numcollected > selected > 0:
|
if self._numcollected > selected:
|
||||||
line += " / %d selected" % selected
|
line += " / %d selected" % selected
|
||||||
if self.isatty:
|
if self.isatty:
|
||||||
self.rewrite(line, bold=True, erase=True)
|
self.rewrite(line, bold=True, erase=True)
|
||||||
|
|
|
@ -773,7 +773,7 @@ class TestLastFailed:
|
||||||
result = pytester.runpytest("--lf", "--lfnf", "none")
|
result = pytester.runpytest("--lf", "--lfnf", "none")
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(
|
||||||
[
|
[
|
||||||
"collected 2 items / 2 deselected",
|
"collected 2 items / 2 deselected / 0 selected",
|
||||||
"run-last-failure: no previously failed tests, deselecting all items.",
|
"run-last-failure: no previously failed tests, deselecting all items.",
|
||||||
"deselected=2",
|
"deselected=2",
|
||||||
"* 2 deselected in *",
|
"* 2 deselected in *",
|
||||||
|
|
|
@ -783,6 +783,33 @@ class TestTerminalFunctional:
|
||||||
result.stdout.no_fnmatch_line("*= 1 deselected =*")
|
result.stdout.no_fnmatch_line("*= 1 deselected =*")
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
|
|
||||||
|
def test_selected_count_with_error(self, pytester: Pytester) -> None:
|
||||||
|
pytester.makepyfile(
|
||||||
|
test_selected_count_3="""
|
||||||
|
def test_one():
|
||||||
|
pass
|
||||||
|
def test_two():
|
||||||
|
pass
|
||||||
|
def test_three():
|
||||||
|
pass
|
||||||
|
""",
|
||||||
|
test_selected_count_error="""
|
||||||
|
5/0
|
||||||
|
def test_foo():
|
||||||
|
pass
|
||||||
|
def test_bar():
|
||||||
|
pass
|
||||||
|
""",
|
||||||
|
)
|
||||||
|
result = pytester.runpytest("-k", "test_t")
|
||||||
|
result.stdout.fnmatch_lines(
|
||||||
|
[
|
||||||
|
"collected 3 items / 1 error / 1 deselected / 2 selected",
|
||||||
|
"* ERROR collecting test_selected_count_error.py *",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
assert result.ret == ExitCode.INTERRUPTED
|
||||||
|
|
||||||
def test_no_skip_summary_if_failure(self, pytester: Pytester) -> None:
|
def test_no_skip_summary_if_failure(self, pytester: Pytester) -> None:
|
||||||
pytester.makepyfile(
|
pytester.makepyfile(
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue