Skip to content

Commit 465fed9

Browse files
committed
Move handling of duplicate files
This removes the hack added in pytest-dev#3802.
1 parent f466105 commit 465fed9

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

src/_pytest/main.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,6 @@ def pytest_ignore_collect(path, config):
278278
if _in_venv(path) and not allow_in_venv:
279279
return True
280280

281-
# Skip duplicate paths.
282-
keepduplicates = config.getoption("keepduplicates")
283-
duplicate_paths = config.pluginmanager._duplicatepaths
284-
if not keepduplicates:
285-
if path in duplicate_paths:
286-
return True
287-
else:
288-
duplicate_paths.add(path)
289-
290281
return False
291282

292283

@@ -556,6 +547,16 @@ def _collectfile(self, path):
556547
if not self.isinitpath(path):
557548
if ihook.pytest_ignore_collect(path=path, config=self.config):
558549
return ()
550+
551+
# Skip duplicate paths.
552+
keepduplicates = self.config.getoption("keepduplicates")
553+
if not keepduplicates:
554+
duplicate_paths = self.config.pluginmanager._duplicatepaths
555+
if path in duplicate_paths:
556+
return ()
557+
else:
558+
duplicate_paths.add(path)
559+
559560
return ihook.pytest_collect_file(path=path, parent=self)
560561

561562
def _recurse(self, path):

src/_pytest/python.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -554,15 +554,6 @@ def isinitpath(self, path):
554554
return path in self.session._initialpaths
555555

556556
def collect(self):
557-
# XXX: HACK!
558-
# Before starting to collect any files from this package we need
559-
# to cleanup the duplicate paths added by the session's collect().
560-
# Proper fix is to not track these as duplicates in the first place.
561-
for path in list(self.session.config.pluginmanager._duplicatepaths):
562-
# if path.parts()[:len(self.fspath.dirpath().parts())] == self.fspath.dirpath().parts():
563-
if path.dirname.startswith(self.name):
564-
self.session.config.pluginmanager._duplicatepaths.remove(path)
565-
566557
this_path = self.fspath.dirpath()
567558
init_module = this_path.join("__init__.py")
568559
if init_module.check(file=1) and path_matches_patterns(

0 commit comments

Comments
 (0)