accept a left out "()" for ids on command line for better compatibility with pytest.vim

This commit is contained in:
holger krekel 2011-02-07 11:09:42 +01:00
parent 3004fe3915
commit 74b9ebc1cd
3 changed files with 23 additions and 0 deletions

View File

@ -4,6 +4,8 @@ Changes between 2.0.0 and 2.0.1
- refine and unify initial capturing so that it works nicely - refine and unify initial capturing so that it works nicely
even if the logging module is used on an early-loaded conftest.py even if the logging module is used on an early-loaded conftest.py
file or plugin. 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 - fix issue12 - show plugin versions with "--version" and
"--traceconfig" and also document how to add extra information "--traceconfig" and also document how to add extra information
to reporting test header to reporting test header

View File

@ -495,9 +495,15 @@ class Session(FSCollector):
node.ihook.pytest_collectstart(collector=node) node.ihook.pytest_collectstart(collector=node)
rep = node.ihook.pytest_make_collect_report(collector=node) rep = node.ihook.pytest_make_collect_report(collector=node)
if rep.passed: if rep.passed:
has_matched = False
for x in rep.result: for x in rep.result:
if x.name == name: if x.name == name:
resultnodes.extend(self.matchnodes([x], nextnames)) 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) node.ihook.pytest_collectreport(report=rep)
return resultnodes return resultnodes

View File

@ -472,6 +472,21 @@ class TestSession:
item2b, = newcol.perform_collect([item.nodeid], genitems=False) item2b, = newcol.perform_collect([item.nodeid], genitems=False)
assert item2b == item2 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: class Test_getinitialnodes:
def test_global_file(self, testdir, tmpdir): def test_global_file(self, testdir, tmpdir):
x = tmpdir.ensure("x.py") x = tmpdir.ensure("x.py")