diff --git a/changelog/11054.bugfix.rst b/changelog/11054.bugfix.rst new file mode 100644 index 00000000000..a8ee04fe304 --- /dev/null +++ b/changelog/11054.bugfix.rst @@ -0,0 +1 @@ +Fixed ``--last-failed``'s "(skipped N files)" functionality for files inside of packages (directories with `__init__.py` files). diff --git a/src/_pytest/cacheprovider.py b/src/_pytest/cacheprovider.py index 719b32f7e0e..940dc5d8782 100755 --- a/src/_pytest/cacheprovider.py +++ b/src/_pytest/cacheprovider.py @@ -213,7 +213,7 @@ def __init__(self, lfplugin: "LFPlugin") -> None: @hookimpl(hookwrapper=True) def pytest_make_collect_report(self, collector: nodes.Collector): - if isinstance(collector, Session): + if isinstance(collector, (Session, Package)): out = yield res: CollectReport = out.get_result() diff --git a/testing/test_cacheprovider.py b/testing/test_cacheprovider.py index 2f8517f9962..f870d7b162e 100644 --- a/testing/test_cacheprovider.py +++ b/testing/test_cacheprovider.py @@ -420,7 +420,13 @@ def test_fail(val): result = pytester.runpytest() result.stdout.fnmatch_lines(["*1 failed in*"]) - def test_terminal_report_lastfailed(self, pytester: Pytester) -> None: + @pytest.mark.parametrize("parent", ("session", "package")) + def test_terminal_report_lastfailed(self, pytester: Pytester, parent: str) -> None: + if parent == "package": + pytester.makepyfile( + __init__="", + ) + test_a = pytester.makepyfile( test_a=""" def test_a1(): pass