Skip to content

Commit a8b9049

Browse files
authored
Merge pull request #9690 from pytest-dev/backport-9628-to-7.0.x
2 parents d18d2c1 + aefb219 commit a8b9049

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

changelog/9626.bugfix.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixed count of selected tests on terminal collection summary when there were errors or skipped modules.
2+
3+
If there were errors or skipped modules on collection, pytest would mistakenly subtract those from the selected count.

src/_pytest/terminal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ def report_collect(self, final: bool = False) -> None:
657657
errors = len(self.stats.get("error", []))
658658
skipped = len(self.stats.get("skipped", []))
659659
deselected = len(self.stats.get("deselected", []))
660-
selected = self._numcollected - errors - skipped - deselected
660+
selected = self._numcollected - deselected
661661
line = "collected " if final else "collecting "
662662
line += (
663663
str(self._numcollected) + " item" + ("" if self._numcollected == 1 else "s")
@@ -668,7 +668,7 @@ def report_collect(self, final: bool = False) -> None:
668668
line += " / %d deselected" % deselected
669669
if skipped:
670670
line += " / %d skipped" % skipped
671-
if self._numcollected > selected > 0:
671+
if self._numcollected > selected:
672672
line += " / %d selected" % selected
673673
if self.isatty:
674674
self.rewrite(line, bold=True, erase=True)

testing/test_cacheprovider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ def pytest_sessionfinish():
773773
result = pytester.runpytest("--lf", "--lfnf", "none")
774774
result.stdout.fnmatch_lines(
775775
[
776-
"collected 2 items / 2 deselected",
776+
"collected 2 items / 2 deselected / 0 selected",
777777
"run-last-failure: no previously failed tests, deselecting all items.",
778778
"deselected=2",
779779
"* 2 deselected in *",

testing/test_terminal.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,33 @@ def test_pass():
751751
result.stdout.no_fnmatch_line("*= 1 deselected =*")
752752
assert result.ret == 0
753753

754+
def test_selected_count_with_error(self, pytester: Pytester) -> None:
755+
pytester.makepyfile(
756+
test_selected_count_3="""
757+
def test_one():
758+
pass
759+
def test_two():
760+
pass
761+
def test_three():
762+
pass
763+
""",
764+
test_selected_count_error="""
765+
5/0
766+
def test_foo():
767+
pass
768+
def test_bar():
769+
pass
770+
""",
771+
)
772+
result = pytester.runpytest("-k", "test_t")
773+
result.stdout.fnmatch_lines(
774+
[
775+
"collected 3 items / 1 error / 1 deselected / 2 selected",
776+
"* ERROR collecting test_selected_count_error.py *",
777+
]
778+
)
779+
assert result.ret == ExitCode.INTERRUPTED
780+
754781
def test_no_skip_summary_if_failure(self, pytester: Pytester) -> None:
755782
pytester.makepyfile(
756783
"""

0 commit comments

Comments
 (0)