Skip to content

Commit fc538c5

Browse files
committed
cacheprovider: fix file-skipping feature for files in packages
`--lf` has a feature where if a certain `Module` (python file) does not contain any failed tests, it is skipped entirely at the collector level instead of being collected and each item skipped individually. When this happens the collection summary looks like this: run-last-failure: rerun previous 1 failure (skipped 1 file) However, this feature didn't work for `Module`s inside of `Package`s, only for those directly beneath the `Session`. Fix #11054.
1 parent 29d16d2 commit fc538c5

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

changelog/11054.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed ``--last-failed``'s "(skipped N files)" functionality for files inside of packages (directories with `__init__.py` files).

src/_pytest/cacheprovider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def __init__(self, lfplugin: "LFPlugin") -> None:
219219

220220
@hookimpl(hookwrapper=True)
221221
def pytest_make_collect_report(self, collector: nodes.Collector):
222-
if isinstance(collector, Session):
222+
if isinstance(collector, (Session, Package)):
223223
out = yield
224224
res: CollectReport = out.get_result()
225225

testing/test_cacheprovider.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,13 @@ def test_fail(val):
420420
result = pytester.runpytest()
421421
result.stdout.fnmatch_lines(["*1 failed in*"])
422422

423-
def test_terminal_report_lastfailed(self, pytester: Pytester) -> None:
423+
@pytest.mark.parametrize("parent", ("session", "package"))
424+
def test_terminal_report_lastfailed(self, pytester: Pytester, parent: str) -> None:
425+
if parent == "package":
426+
pytester.makepyfile(
427+
__init__="",
428+
)
429+
424430
test_a = pytester.makepyfile(
425431
test_a="""
426432
def test_a1(): pass

0 commit comments

Comments
 (0)