From e04182364338ed9cd2a63945204701c99e297f21 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 25 Oct 2018 20:03:14 +0200 Subject: [PATCH] Move handling of duplicate files This removes the hack added in https://github.com/pytest-dev/pytest/pull/3802. Adjusts test: - it appears to not have been changed to 7 intentionally. - removes XXX comment, likely not relevant anymore since 6dac7743. --- src/_pytest/main.py | 19 ++++++++++--------- src/_pytest/python.py | 9 --------- testing/test_session.py | 2 +- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 8d4176aeafe..fb9328714c7 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -278,15 +278,6 @@ def pytest_ignore_collect(path, config): if _in_venv(path) and not allow_in_venv: return True - # Skip duplicate paths. - keepduplicates = config.getoption("keepduplicates") - duplicate_paths = config.pluginmanager._duplicatepaths - if not keepduplicates: - if path in duplicate_paths: - return True - else: - duplicate_paths.add(path) - return False @@ -556,6 +547,16 @@ def _collectfile(self, path): if not self.isinitpath(path): if ihook.pytest_ignore_collect(path=path, config=self.config): return () + + # Skip duplicate paths. + keepduplicates = self.config.getoption("keepduplicates") + if not keepduplicates: + duplicate_paths = self.config.pluginmanager._duplicatepaths + if path in duplicate_paths: + return () + else: + duplicate_paths.add(path) + return ihook.pytest_collect_file(path=path, parent=self) def _recurse(self, path): diff --git a/src/_pytest/python.py b/src/_pytest/python.py index ef3e3a730b5..c7b4f073359 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -554,15 +554,6 @@ def isinitpath(self, path): return path in self.session._initialpaths def collect(self): - # XXX: HACK! - # Before starting to collect any files from this package we need - # to cleanup the duplicate paths added by the session's collect(). - # Proper fix is to not track these as duplicates in the first place. - for path in list(self.session.config.pluginmanager._duplicatepaths): - # if path.parts()[:len(self.fspath.dirpath().parts())] == self.fspath.dirpath().parts(): - if path.dirname.startswith(self.name): - self.session.config.pluginmanager._duplicatepaths.remove(path) - this_path = self.fspath.dirpath() init_module = this_path.join("__init__.py") if init_module.check(file=1) and path_matches_patterns( diff --git a/testing/test_session.py b/testing/test_session.py index 50ce91534bf..72d5cda729c 100644 --- a/testing/test_session.py +++ b/testing/test_session.py @@ -218,7 +218,7 @@ class TestY(TestX): started = reprec.getcalls("pytest_collectstart") finished = reprec.getreports("pytest_collectreport") assert len(started) == len(finished) - assert len(started) == 7 # XXX extra TopCollector + assert len(started) == 8 colfail = [x for x in finished if x.failed] assert len(colfail) == 1