diff --git a/CHANGELOG b/CHANGELOG index 3e3d0fd6a..9ba4dae81 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,8 @@ Changes between 2.0.0 and 2.0.1 - refine and unify initial capturing so that it works nicely even if the logging module is used on an early-loaded conftest.py file or plugin. +- allow to omit "()" in test ids to allow for uniform test ids + as produced by Alfredo's nice pytest.vim plugin. - fix issue12 - show plugin versions with "--version" and "--traceconfig" and also document how to add extra information to reporting test header diff --git a/_pytest/main.py b/_pytest/main.py index 23775347b..d1ccc4307 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -495,9 +495,15 @@ class Session(FSCollector): node.ihook.pytest_collectstart(collector=node) rep = node.ihook.pytest_make_collect_report(collector=node) if rep.passed: + has_matched = False for x in rep.result: if x.name == name: resultnodes.extend(self.matchnodes([x], nextnames)) + has_matched = True + # XXX accept IDs that don't have "()" for class instances + if not has_matched and len(rep.result) == 1 and x.name == "()": + nextnames.insert(0, name) + resultnodes.extend(self.matchnodes([x], nextnames)) node.ihook.pytest_collectreport(report=rep) return resultnodes diff --git a/testing/test_collection.py b/testing/test_collection.py index 71c58e128..a5e79e867 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -472,6 +472,21 @@ class TestSession: item2b, = newcol.perform_collect([item.nodeid], genitems=False) assert item2b == item2 + def test_find_byid_without_instance_parents(self, testdir): + p = testdir.makepyfile(""" + class TestClass: + def test_method(self): + pass + """) + arg = p.basename + ("::TestClass::test_method") + config = testdir.parseconfig(arg) + rcol = Session(config) + rcol.perform_collect() + items = rcol.items + assert len(items) == 1 + item, = items + assert item.nodeid.endswith("TestClass::()::test_method") + class Test_getinitialnodes: def test_global_file(self, testdir, tmpdir): x = tmpdir.ensure("x.py")