fix doctest IDs, also fix tree traversal and remove dead code

This commit is contained in:
holger krekel 2010-11-17 18:24:28 +01:00
parent acd286f82f
commit 2a825169b2
4 changed files with 63 additions and 14 deletions

View File

@ -33,11 +33,6 @@ class ReprFailDoctest(TerminalRepr):
self.reprlocation.toterminal(tw)
class DoctestItem(pytest.Item):
def __init__(self, path, parent):
name = self.__class__.__name__ + ":" + path.basename
super(DoctestItem, self).__init__(name=name, parent=parent)
self.fspath = path
def repr_failure(self, excinfo):
if excinfo.errisinstance(py.std.doctest.DocTestFailure):
doctestfailure = excinfo.value
@ -67,13 +62,13 @@ class DoctestItem(pytest.Item):
def reportinfo(self):
return self.fspath, None, "[doctest]"
class DoctestTextfile(DoctestItem):
class DoctestTextfile(DoctestItem, pytest.File):
def runtest(self):
failed, tot = py.std.doctest.testfile(
str(self.fspath), module_relative=False,
raise_on_error=True, verbose=0)
class DoctestModule(DoctestItem):
class DoctestModule(DoctestItem, pytest.File):
def runtest(self):
module = self.fspath.pyimport()
failed, tot = py.std.doctest.testmod(

View File

@ -482,7 +482,8 @@ class Session(FSCollector):
resultnodes = []
for node in matching:
if isinstance(node, pytest.Item):
resultnodes.append(node)
if not names:
resultnodes.append(node)
continue
assert isinstance(node, pytest.Collector)
node.ihook.pytest_collectstart(collector=node)
@ -508,5 +509,3 @@ class Session(FSCollector):
for x in self.genitems(subnode):
yield x
node.ihook.pytest_collectreport(report=rep)
Session = Session

View File

@ -372,3 +372,22 @@ class TestInvocationVariants:
""")
reprec = testdir.inline_run(testpath)
reprec.assertoutcome(passed=1)
def test_doctest_id(self, testdir):
testdir.makefile('.txt', """
>>> x=3
>>> x
4
""")
result = testdir.runpytest("-rf")
lines = result.stdout.str().splitlines()
for line in lines:
if line.startswith("FAIL "):
testid = line[5:].strip()
break
result = testdir.runpytest(testid, '-rf')
result.stdout.fnmatch_lines([
line,
"*1 failed*",
])

View File

@ -472,10 +472,6 @@ class TestSession:
item2b, = newcol.perform_collect([item.nodeid], genitems=False)
assert item2b == item2
def getargnode(collection, arg):
argpath = arg.relto(collection.fspath)
return collection.perform_collect([argpath], genitems=False)[0]
class Test_getinitialnodes:
def test_global_file(self, testdir, tmpdir):
x = tmpdir.ensure("x.py")
@ -552,3 +548,43 @@ class Test_genitems:
s = items[0].getmodpath(stopatmodule=False)
assert s.endswith("test_example_items1.testone")
print(s)
def test_matchnodes_two_collections_same_file(testdir):
testdir.makeconftest("""
import pytest
def pytest_configure(config):
config.pluginmanager.register(Plugin2())
class Plugin2:
def pytest_collect_file(self, path, parent):
if path.ext == ".abc":
return MyFile2(path, parent)
def pytest_collect_file(path, parent):
if path.ext == ".abc":
return MyFile1(path, parent)
class MyFile1(pytest.Item, pytest.File):
def runtest(self):
pass
class MyFile2(pytest.File):
def collect(self):
return [Item2("hello", parent=self)]
class Item2(pytest.Item):
def runtest(self):
pass
""")
p = testdir.makefile(".abc", "")
result = testdir.runpytest()
assert result.ret == 0
result.stdout.fnmatch_lines([
"*2 passed*",
])
res = testdir.runpytest("%s::hello" % p.basename)
res.stdout.fnmatch_lines([
"*1 passed*",
])