From c02e8d8b0d4a50cb802b901f78412448612d03ed Mon Sep 17 00:00:00 2001 From: turturica Date: Mon, 16 Apr 2018 11:44:05 -0700 Subject: [PATCH] Fix test collection when tests are passed as IDs at the command line. Note this is still broken due to #3358. --- _pytest/main.py | 7 +++++-- testing/python/collect.py | 2 +- testing/test_collection.py | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/_pytest/main.py b/_pytest/main.py index a18328867..5cad8bae3 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -423,9 +423,12 @@ class Session(nodes.FSCollector): else: assert argpath.check(file=1) pkginit = argpath.dirpath().join('__init__.py') - if not self.isinitpath(argpath) and pkginit.exists(): + if not self.isinitpath(pkginit): + self._initialpaths.add(pkginit) + if pkginit.exists(): for x in self._collectfile(pkginit): - yield x + for y in self.matchnodes(x._collectfile(argpath), names): + yield y else: for x in self.matchnodes(self._collectfile(argpath), names): yield x diff --git a/testing/python/collect.py b/testing/python/collect.py index de40486a8..96928569f 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -927,7 +927,7 @@ def test_setup_only_available_in_subdir(testdir): def test_modulecol_roundtrip(testdir): - modcol = testdir.getmodulecol("pass", withinit=True) + modcol = testdir.getmodulecol("pass", withinit=False) trail = modcol.nodeid newcol = modcol.session.perform_collect([trail], genitems=0)[0] assert modcol.name == newcol.name diff --git a/testing/test_collection.py b/testing/test_collection.py index b9d0a9470..3efef08b2 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -587,7 +587,7 @@ class Test_getinitialnodes(object): col = testdir.getnode(config, x) assert isinstance(col, pytest.Module) assert col.name == 'x.py' - assert col.parent.parent is None + assert col.parent.parent.parent is None for col in col.listchain(): assert col.config is config