diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 9599fa161..105891e46 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -482,6 +482,8 @@ class Session(nodes.FSCollector): self.trace.root.indent -= 1 def _collect(self, arg): + from _pytest.python import Package + names = self._parsearg(arg) argpath = names.pop(0) paths = [] @@ -503,7 +505,7 @@ class Session(nodes.FSCollector): root = self._node_cache[pkginit] else: col = root._collectfile(pkginit) - if col: + if col and isinstance(col, Package): root = col[0] self._node_cache[root.fspath] = root diff --git a/testing/test_collection.py b/testing/test_collection.py index 6480cc85d..23d82cb14 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -647,7 +647,7 @@ class Test_getinitialnodes(object): col = testdir.getnode(config, x) assert isinstance(col, pytest.Module) assert col.name == "x.py" - assert col.parent.parent.parent is None + assert col.parent.parent is None for col in col.listchain(): assert col.config is config