Skip to content

Commit b5ff089

Browse files
authored
Merge pull request #11069 from bluetech/lf-file
cacheprovider: make file-skipping work with any File, not just Modules
2 parents 4b823a4 + fda8024 commit b5ff089

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

changelog/11068.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed the ``--last-failed`` whole-file skipping functionality ("skipped N files") for :ref:`non-python test files <non-python tests>`.

src/_pytest/cacheprovider.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from _pytest.fixtures import fixture
2828
from _pytest.fixtures import FixtureRequest
2929
from _pytest.main import Session
30-
from _pytest.python import Module
30+
from _pytest.nodes import File
3131
from _pytest.python import Package
3232
from _pytest.reports import TestReport
3333

@@ -242,7 +242,7 @@ def sort_key(node: Union[nodes.Item, nodes.Collector]) -> bool:
242242
)
243243
return
244244

245-
elif isinstance(collector, Module):
245+
elif isinstance(collector, File):
246246
if collector.path in self.lfplugin._last_failed_paths:
247247
out = yield
248248
res = out.get_result()
@@ -280,9 +280,9 @@ def __init__(self, lfplugin: "LFPlugin") -> None:
280280
def pytest_make_collect_report(
281281
self, collector: nodes.Collector
282282
) -> Optional[CollectReport]:
283-
# Packages are Modules, but we only want to skip test-bearing Modules,
283+
# Packages are Files, but we only want to skip test-bearing Files,
284284
# so don't filter Packages.
285-
if isinstance(collector, Module) and not isinstance(collector, Package):
285+
if isinstance(collector, File) and not isinstance(collector, Package):
286286
if collector.path not in self.lfplugin._last_failed_paths:
287287
self.lfplugin._skipped_files += 1
288288

testing/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def get_write_msg(self, idx):
105105

106106

107107
@pytest.fixture
108-
def dummy_yaml_custom_test(pytester: Pytester):
108+
def dummy_yaml_custom_test(pytester: Pytester) -> None:
109109
"""Writes a conftest file that collects and executes a dummy yaml test.
110110
111111
Taken from the docs, but stripped down to the bare minimum, useful for

testing/test_cacheprovider.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,28 @@ def test_packages(self, pytester: Pytester) -> None:
10851085
result = pytester.runpytest("--lf")
10861086
result.assert_outcomes(failed=3)
10871087

1088+
def test_non_python_file_skipped(
1089+
self,
1090+
pytester: Pytester,
1091+
dummy_yaml_custom_test: None,
1092+
) -> None:
1093+
pytester.makepyfile(
1094+
**{
1095+
"test_bad.py": """def test_bad(): assert False""",
1096+
},
1097+
)
1098+
result = pytester.runpytest()
1099+
result.stdout.fnmatch_lines(["collected 2 items", "* 1 failed, 1 passed in *"])
1100+
1101+
result = pytester.runpytest("--lf")
1102+
result.stdout.fnmatch_lines(
1103+
[
1104+
"collected 1 item",
1105+
"run-last-failure: rerun previous 1 failure (skipped 1 file)",
1106+
"* 1 failed in *",
1107+
]
1108+
)
1109+
10881110

10891111
class TestNewFirst:
10901112
def test_newfirst_usecase(self, pytester: Pytester) -> None:

0 commit comments

Comments
 (0)