Merge pull request #7915 from bluetech/fix-lf-package
cacheprovider: fix some files in packages getting lost from --lf
This commit is contained in:
		
						commit
						a66b6b857a
					
				| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					Fixed an issue where some files in packages are getting lost from ``--lf`` even though they contain tests that failed. Regressed in pytest 5.4.0.
 | 
				
			||||||
| 
						 | 
					@ -28,6 +28,7 @@ from _pytest.config.argparsing import Parser
 | 
				
			||||||
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.python import Module
 | 
				
			||||||
 | 
					from _pytest.python import Package
 | 
				
			||||||
from _pytest.reports import TestReport
 | 
					from _pytest.reports import TestReport
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -232,7 +233,10 @@ class LFPluginCollSkipfiles:
 | 
				
			||||||
    def pytest_make_collect_report(
 | 
					    def pytest_make_collect_report(
 | 
				
			||||||
        self, collector: nodes.Collector
 | 
					        self, collector: nodes.Collector
 | 
				
			||||||
    ) -> Optional[CollectReport]:
 | 
					    ) -> Optional[CollectReport]:
 | 
				
			||||||
        if isinstance(collector, Module):
 | 
					        # Packages are Modules, but _last_failed_paths only contains
 | 
				
			||||||
 | 
					        # test-bearing paths and doesn't try to include the paths of their
 | 
				
			||||||
 | 
					        # packages, so don't filter them.
 | 
				
			||||||
 | 
					        if isinstance(collector, Module) and not isinstance(collector, Package):
 | 
				
			||||||
            if Path(str(collector.fspath)) not in self.lfplugin._last_failed_paths:
 | 
					            if Path(str(collector.fspath)) not in self.lfplugin._last_failed_paths:
 | 
				
			||||||
                self.lfplugin._skipped_files += 1
 | 
					                self.lfplugin._skipped_files += 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,6 +7,7 @@ import py
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import pytest
 | 
					import pytest
 | 
				
			||||||
from _pytest.config import ExitCode
 | 
					from _pytest.config import ExitCode
 | 
				
			||||||
 | 
					from _pytest.pytester import Pytester
 | 
				
			||||||
from _pytest.pytester import Testdir
 | 
					from _pytest.pytester import Testdir
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pytest_plugins = ("pytester",)
 | 
					pytest_plugins = ("pytester",)
 | 
				
			||||||
| 
						 | 
					@ -982,6 +983,36 @@ class TestLastFailed:
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        assert result.ret == 0
 | 
					        assert result.ret == 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_packages(self, pytester: Pytester) -> None:
 | 
				
			||||||
 | 
					        """Regression test for #7758.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        The particular issue here was that Package nodes were included in the
 | 
				
			||||||
 | 
					        filtering, being themselves Modules for the __init__.py, even if they
 | 
				
			||||||
 | 
					        had failed Modules in them.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        The tests includes a test in an __init__.py file just to make sure the
 | 
				
			||||||
 | 
					        fix doesn't somehow regress that, it is not critical for the issue.
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        pytester.makepyfile(
 | 
				
			||||||
 | 
					            **{
 | 
				
			||||||
 | 
					                "__init__.py": "",
 | 
				
			||||||
 | 
					                "a/__init__.py": "def test_a_init(): assert False",
 | 
				
			||||||
 | 
					                "a/test_one.py": "def test_1(): assert False",
 | 
				
			||||||
 | 
					                "b/__init__.py": "",
 | 
				
			||||||
 | 
					                "b/test_two.py": "def test_2(): assert False",
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        pytester.makeini(
 | 
				
			||||||
 | 
					            """
 | 
				
			||||||
 | 
					            [pytest]
 | 
				
			||||||
 | 
					            python_files = *.py
 | 
				
			||||||
 | 
					            """
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        result = pytester.runpytest()
 | 
				
			||||||
 | 
					        result.assert_outcomes(failed=3)
 | 
				
			||||||
 | 
					        result = pytester.runpytest("--lf")
 | 
				
			||||||
 | 
					        result.assert_outcomes(failed=3)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestNewFirst:
 | 
					class TestNewFirst:
 | 
				
			||||||
    def test_newfirst_usecase(self, testdir):
 | 
					    def test_newfirst_usecase(self, testdir):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue