diff --git a/py/_plugin/pytest_python.py b/py/_plugin/pytest_python.py index 337d4919f..cb9661826 100644 --- a/py/_plugin/pytest_python.py +++ b/py/_plugin/pytest_python.py @@ -664,7 +664,8 @@ class FuncargRequest: def showfuncargs(config): from py._test.session import Collection collection = Collection(config) - colitem = collection.getinitialnodes()[0] + firstid = collection._normalizearg(config.args[0]) + colitem = collection.getbyid(firstid)[0] curdir = py.path.local() tw = py.io.TerminalWriter() plugins = getplugins(colitem, withpy=True) diff --git a/py/_test/session.py b/py/_test/session.py index cd6320eb1..de8703cdd 100644 --- a/py/_test/session.py +++ b/py/_test/session.py @@ -160,13 +160,6 @@ class Collection: matching = l return matching - def getinitialnodes(self): - idlist = [self._normalizearg(arg) for arg in self.config.args] - nodes = [] - for id in idlist: - nodes.extend(self.getbyid(id)) - return nodes - def perform_collect(self): nodes = [] for arg in self.config.args: diff --git a/testing/plugin/test_pytest_python.py b/testing/plugin/test_pytest_python.py index 1e6443f03..5d8c68bed 100644 --- a/testing/plugin/test_pytest_python.py +++ b/testing/plugin/test_pytest_python.py @@ -1127,3 +1127,10 @@ class TestReportInfo: pass """ +def test_show_funcarg(testdir): + result = testdir.runpytest("--funcargs") + result.stdout.fnmatch_lines([ + "*tmpdir*", + "*temporary directory*", + ] + ) diff --git a/testing/plugin/test_pytest_terminal.py b/testing/plugin/test_pytest_terminal.py index c54e5729d..1a0fbea46 100644 --- a/testing/plugin/test_pytest_terminal.py +++ b/testing/plugin/test_pytest_terminal.py @@ -517,14 +517,6 @@ def test_trace_reporting(testdir): ]) assert result.ret == 0 -def test_show_funcarg(testdir, option): - args = option.args + ["--funcargs"] - result = testdir.runpytest(*args) - result.stdout.fnmatch_lines([ - "*tmpdir*", - "*temporary directory*", - ] - ) class TestGenericReporting: """ this test class can be subclassed with a different option diff --git a/testing/test_collection.py b/testing/test_collection.py index a346ad4e0..08df79b83 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -198,40 +198,37 @@ class Test_gettopdir: assert gettopdir(["%s::xyc::abc" % c]) == a assert gettopdir(["%s::xyc" % c, "%s::abc" % Z]) == tmp +def getargnode(collection, arg): + return collection.getbyid(collection._normalizearg(str(arg)))[0] + class Test_getinitialnodes: def test_onedir(self, testdir): config = testdir.reparseconfig([testdir.tmpdir]) - colitems = Collection(config).getinitialnodes() - assert len(colitems) == 1 - col = colitems[0] + c = Collection(config) + col = getargnode(c, testdir.tmpdir) assert isinstance(col, py.test.collect.Directory) for col in col.listchain(): assert col.config is config - - def test_twodirs(self, testdir, tmpdir): - config = testdir.reparseconfig([tmpdir, tmpdir]) - colitems = Collection(config).getinitialnodes() - assert len(colitems) == 2 - col1, col2 = colitems - assert col1.name == col2.name - assert col1.parent == col2.parent + t2 = getargnode(c, testdir.tmpdir) + assert col == t2 def test_curdir_and_subdir(self, testdir, tmpdir): a = tmpdir.ensure("a", dir=1) config = testdir.reparseconfig([tmpdir, a]) - colitems = Collection(config).getinitialnodes() - assert len(colitems) == 2 - col1, col2 = colitems + c = Collection(config) + + col1 = getargnode(c, tmpdir) + col2 = getargnode(c, a) assert col1.name == tmpdir.basename assert col2.name == 'a' - for col in colitems: + for col in (col1, col2): for subcol in col.listchain(): assert col.config is config def test_global_file(self, testdir, tmpdir): x = tmpdir.ensure("x.py") config = testdir.reparseconfig([x]) - col, = Collection(config).getinitialnodes() + col = getargnode(Collection(config), x) assert isinstance(col, py.test.collect.Module) assert col.name == 'x.py' assert col.parent.name == tmpdir.basename @@ -242,7 +239,7 @@ class Test_getinitialnodes: def test_global_dir(self, testdir, tmpdir): x = tmpdir.ensure("a", dir=1) config = testdir.reparseconfig([x]) - col, = Collection(config).getinitialnodes() + col = getargnode(Collection(config), x) assert isinstance(col, py.test.collect.Directory) print(col.listchain()) assert col.name == 'a' @@ -254,7 +251,7 @@ class Test_getinitialnodes: x = tmpdir.ensure("x.py") tmpdir.ensure("__init__.py") config = testdir.reparseconfig([x]) - col, = Collection(config).getinitialnodes() + col = getargnode(Collection(config), x) assert isinstance(col, py.test.collect.Module) assert col.name == 'x.py' assert col.parent.name == x.dirpath().basename