Skip to content

Commit 8c9efd8

Browse files
committed
Only call _collectfile on package instances
As discussed in #3751, this feels like a hack, pushing it only so we can see how it fares on CI and if there are better solutions out there
1 parent e1ad1a1 commit 8c9efd8

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/_pytest/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,8 @@ def collect(self):
482482
self.trace.root.indent -= 1
483483

484484
def _collect(self, arg):
485+
from _pytest.python import Package
486+
485487
names = self._parsearg(arg)
486488
argpath = names.pop(0)
487489
paths = []
@@ -503,7 +505,7 @@ def _collect(self, arg):
503505
root = self._node_cache[pkginit]
504506
else:
505507
col = root._collectfile(pkginit)
506-
if col:
508+
if col and isinstance(col, Package):
507509
root = col[0]
508510
self._node_cache[root.fspath] = root
509511

testing/test_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ def test_pkgfile(self, testdir):
647647
col = testdir.getnode(config, x)
648648
assert isinstance(col, pytest.Module)
649649
assert col.name == "x.py"
650-
assert col.parent.parent.parent is None
650+
assert col.parent.parent is None
651651
for col in col.listchain():
652652
assert col.config is config
653653

0 commit comments

Comments
 (0)