Skip to content

Commit c02e8d8

Browse files
turturicaturturica
turturica
authored and
turturica
committed
Fix test collection when tests are passed as IDs at the command line. Note this is still broken due to #3358.
1 parent 35df2cd commit c02e8d8

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

_pytest/main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,12 @@ def _collect(self, arg):
423423
else:
424424
assert argpath.check(file=1)
425425
pkginit = argpath.dirpath().join('__init__.py')
426-
if not self.isinitpath(argpath) and pkginit.exists():
426+
if not self.isinitpath(pkginit):
427+
self._initialpaths.add(pkginit)
428+
if pkginit.exists():
427429
for x in self._collectfile(pkginit):
428-
yield x
430+
for y in self.matchnodes(x._collectfile(argpath), names):
431+
yield y
429432
else:
430433
for x in self.matchnodes(self._collectfile(argpath), names):
431434
yield x

testing/python/collect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ def pytest_runtest_teardown(item):
927927

928928

929929
def test_modulecol_roundtrip(testdir):
930-
modcol = testdir.getmodulecol("pass", withinit=True)
930+
modcol = testdir.getmodulecol("pass", withinit=False)
931931
trail = modcol.nodeid
932932
newcol = modcol.session.perform_collect([trail], genitems=0)[0]
933933
assert modcol.name == newcol.name

testing/test_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ def test_pkgfile(self, testdir):
587587
col = testdir.getnode(config, x)
588588
assert isinstance(col, pytest.Module)
589589
assert col.name == 'x.py'
590-
assert col.parent.parent is None
590+
assert col.parent.parent.parent is None
591591
for col in col.listchain():
592592
assert col.config is config
593593

0 commit comments

Comments
 (0)