Skip to content

Commit

Permalink
cacheprovider: fix file-skipping feature for files in packages
Browse files Browse the repository at this point in the history
`--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 pytest-dev#11054.
  • Loading branch information
bluetech committed May 29, 2023
1 parent 29d16d2 commit fc538c5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/11054.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed ``--last-failed``'s "(skipped N files)" functionality for files inside of packages (directories with `__init__.py` files).
2 changes: 1 addition & 1 deletion src/_pytest/cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,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()

Expand Down
8 changes: 7 additions & 1 deletion testing/test_cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fc538c5

Please sign in to comment.