Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,18 @@ def collect(self):
arg = "::".join(map(str, initialpart))
self.trace("processing argument", arg)
self.trace.root.indent += 1

keepduplicates = self.config.getoption("keepduplicates")
if not keepduplicates:
duplicate_paths = self.config.pluginmanager._duplicatepaths

try:
for x in self._collect(arg):
if not keepduplicates:
dupe_key = (type(x), x.fspath)
if dupe_key in duplicate_paths:
continue
duplicate_paths.add(dupe_key)
yield x
except NoMatch:
# we are inside a make_report hook so
Expand Down Expand Up @@ -503,7 +513,7 @@ def _collect(self, arg):
pkginit = parent.join("__init__.py")
if pkginit.isfile():
if pkginit not in self._node_cache:
col = self._collectfile(pkginit, handle_dupes=False)
col = self._collectfile(pkginit)
if col:
if isinstance(col[0], Package):
self._pkg_roots[parent] = col[0]
Expand Down Expand Up @@ -572,21 +582,11 @@ def filter_(f):
for y in m:
yield y

def _collectfile(self, path, handle_dupes=True):
def _collectfile(self, path):
ihook = self.gethookproxy(path)
if not self.isinitpath(path):
if ihook.pytest_ignore_collect(path=path, config=self.config):
return ()

if handle_dupes:
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, dirpath):
Expand Down
11 changes: 1 addition & 10 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,21 +545,12 @@ def gethookproxy(self, fspath):
proxy = self.config.hook
return proxy

def _collectfile(self, path, handle_dupes=True):
def _collectfile(self, path):
ihook = self.gethookproxy(path)
if not self.isinitpath(path):
if ihook.pytest_ignore_collect(path=path, config=self.config):
return ()

if handle_dupes:
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)

if self.fspath == path: # __init__.py
return [self]

Expand Down
8 changes: 8 additions & 0 deletions testing/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ def pytest_collect_file(path, parent):
node = testdir.getpathnode(hello)
assert isinstance(node, pytest.File)
assert node.name == "hello.xxx"

# HACK: unset _duplicatepaths, which appears to be necessary for this
# specific test setup?!
assert node.session.config.pluginmanager._duplicatepaths == {
(type(node), hello)
}
node.session.config.pluginmanager._duplicatepaths = set()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will losen that a bit, but still wonder if that's expected/sane.

diff --git a/testing/test_collection.py b/testing/test_collection.py
index 659d39c8..fbc8cc7b 100644
--- a/testing/test_collection.py
+++ b/testing/test_collection.py
@@ -101,9 +101,7 @@ def pytest_collect_file(path, parent):
 
         # HACK: unset _duplicatepaths, which appears to be necessary for this
         #       specific test setup?!
-        assert node.session.config.pluginmanager._duplicatepaths == {
-            (type(node), hello)
-        }
+        assert len(node.session.config.pluginmanager._duplicatepaths) == 1

It is likely due to this specific test setup, right? (also causes #4331)

nodes = node.session.perform_collect([node.nodeid], genitems=False)
assert len(nodes) == 1
assert isinstance(nodes[0], pytest.File)
Expand Down