cacheprovider: make file-skipping work with any File, not just Modules

No reason for `--lf`'s whole-file-skipping feature to not for for
non-Python files.

Fix #11068.
This commit is contained in:
Ran Benita 2023-06-02 11:41:36 +03:00
parent 4b823a42ce
commit fda8024622
4 changed files with 28 additions and 5 deletions

View File

@ -0,0 +1 @@
Fixed the ``--last-failed`` whole-file skipping functionality ("skipped N files") for :ref:`non-python test files <non-python tests>`.

View File

@ -27,7 +27,7 @@ from _pytest.deprecated import check_ispytest
from _pytest.fixtures import fixture from _pytest.fixtures import fixture
from _pytest.fixtures import FixtureRequest from _pytest.fixtures import FixtureRequest
from _pytest.main import Session from _pytest.main import Session
from _pytest.python import Module from _pytest.nodes import File
from _pytest.python import Package from _pytest.python import Package
from _pytest.reports import TestReport from _pytest.reports import TestReport
@ -242,7 +242,7 @@ class LFPluginCollWrapper:
) )
return return
elif isinstance(collector, Module): elif isinstance(collector, File):
if collector.path in self.lfplugin._last_failed_paths: if collector.path in self.lfplugin._last_failed_paths:
out = yield out = yield
res = out.get_result() res = out.get_result()
@ -280,9 +280,9 @@ class LFPluginCollSkipfiles:
def pytest_make_collect_report( def pytest_make_collect_report(
self, collector: nodes.Collector self, collector: nodes.Collector
) -> Optional[CollectReport]: ) -> Optional[CollectReport]:
# Packages are Modules, but we only want to skip test-bearing Modules, # Packages are Files, but we only want to skip test-bearing Files,
# so don't filter Packages. # so don't filter Packages.
if isinstance(collector, Module) and not isinstance(collector, Package): if isinstance(collector, File) and not isinstance(collector, Package):
if collector.path not in self.lfplugin._last_failed_paths: if collector.path not in self.lfplugin._last_failed_paths:
self.lfplugin._skipped_files += 1 self.lfplugin._skipped_files += 1

View File

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

View File

@ -1085,6 +1085,28 @@ class TestLastFailed:
result = pytester.runpytest("--lf") result = pytester.runpytest("--lf")
result.assert_outcomes(failed=3) result.assert_outcomes(failed=3)
def test_non_python_file_skipped(
self,
pytester: Pytester,
dummy_yaml_custom_test: None,
) -> None:
pytester.makepyfile(
**{
"test_bad.py": """def test_bad(): assert False""",
},
)
result = pytester.runpytest()
result.stdout.fnmatch_lines(["collected 2 items", "* 1 failed, 1 passed in *"])
result = pytester.runpytest("--lf")
result.stdout.fnmatch_lines(
[
"collected 1 item",
"run-last-failure: rerun previous 1 failure (skipped 1 file)",
"* 1 failed in *",
]
)
class TestNewFirst: class TestNewFirst:
def test_newfirst_usecase(self, pytester: Pytester) -> None: def test_newfirst_usecase(self, pytester: Pytester) -> None: