Skip to content

Commit bfd0add

Browse files
turturicaturturica
turturica
authored and
turturica
committed
Fix test collection from packages mixed with directories. pytest-dev#3768 and pytest-dev#3789
1 parent 4d8903f commit bfd0add

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/_pytest/python.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,6 @@ def pytest_pycollect_makemodule(path, parent):
216216
return Module(path, parent)
217217

218218

219-
def pytest_ignore_collect(path, config):
220-
# Skip duplicate packages.
221-
keepduplicates = config.getoption("keepduplicates")
222-
if keepduplicates:
223-
duplicate_paths = config.pluginmanager._duplicatepaths
224-
if path.basename == "__init__.py":
225-
if path in duplicate_paths:
226-
return True
227-
else:
228-
duplicate_paths.add(path)
229-
230-
231219
@hookimpl(hookwrapper=True)
232220
def pytest_pycollect_makeitem(collector, name, obj):
233221
outcome = yield
@@ -554,9 +542,7 @@ def __init__(self, fspath, parent=None, config=None, session=None, nodeid=None):
554542
self.name = fspath.dirname
555543
self.trace = session.trace
556544
self._norecursepatterns = session._norecursepatterns
557-
for path in list(session.config.pluginmanager._duplicatepaths):
558-
if path.dirname == fspath.dirname and path != fspath:
559-
session.config.pluginmanager._duplicatepaths.remove(path)
545+
self.fspath = fspath
560546

561547
def _recurse(self, path):
562548
ihook = self.gethookproxy(path.dirpath())
@@ -594,6 +580,15 @@ def isinitpath(self, path):
594580
return path in self.session._initialpaths
595581

596582
def collect(self):
583+
# XXX: HACK!
584+
# Before starting to collect any files from this package we need
585+
# to cleanup the duplicate paths added by the session's collect().
586+
# Proper fix is to not track these as duplicates in the first place.
587+
for path in list(self.session.config.pluginmanager._duplicatepaths):
588+
# if path.parts()[:len(self.fspath.dirpath().parts())] == self.fspath.dirpath().parts():
589+
if path.dirname.startswith(self.name):
590+
self.session.config.pluginmanager._duplicatepaths.remove(path)
591+
597592
this_path = self.fspath.dirpath()
598593
pkg_prefix = None
599594
for path in this_path.visit(rec=self._recurse, bf=True, sort=True):

0 commit comments

Comments
 (0)