diff options
author | Ran Benita <ran@unusedvar.com> | 2020-10-19 18:34:03 +0300 |
---|---|---|
committer | Ran Benita <ran@unusedvar.com> | 2020-10-19 19:02:43 +0300 |
commit | afaabdda8cdf2b1e333a4aad550e5750d2ecd510 (patch) | |
tree | 6460378d5922e595e69643a3ac693839ac177a90 /src/_pytest | |
parent | f453460ae7618df34d2645266f9811dd3c39090e (diff) | |
download | pytest-afaabdda8cdf2b1e333a4aad550e5750d2ecd510.tar.gz |
cacheprovider: fix some files in packages getting lost from --lf
--lf has an optimization where it skips collecting Modules (python
files) which don't contain failing tests. The optimization works by
getting the paths of all cached failed tests and skipping the collection
of Modules whose path is not included in that list.
In pytest, Package nodes are Module nodes with the fspath being the file
`<package dir>/__init__.py`. Since it's a Module the logic above
triggered for it, and because it's an `__init__.py` file which is
unlikely to have any failing tests in it, it is skipped, which causes
its entire directory to be skipped, including any Modules inside it with
failing tests.
Fix by special-casing Packages to never filter. This means entire
Packages are never filtered, the Modules themselves are always checked.
It is reasonable to consider an optimization which does filter entire
packages bases on parent paths etc. but this wouldn't actually save any
real work so is really not worth it.
Diffstat (limited to 'src/_pytest')
-rwxr-xr-x | src/_pytest/cacheprovider.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/_pytest/cacheprovider.py b/src/_pytest/cacheprovider.py index 20f0c71d3..09f3d6653 100755 --- a/src/_pytest/cacheprovider.py +++ b/src/_pytest/cacheprovider.py @@ -28,6 +28,7 @@ from _pytest.config.argparsing import Parser from _pytest.fixtures import FixtureRequest from _pytest.main import Session from _pytest.python import Module +from _pytest.python import Package from _pytest.reports import TestReport @@ -232,7 +233,10 @@ class LFPluginCollSkipfiles: def pytest_make_collect_report( self, collector: nodes.Collector ) -> 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: self.lfplugin._skipped_files += 1 |