fix doctest IDs, also fix tree traversal and remove dead code
This commit is contained in:
parent
acd286f82f
commit
2a825169b2
|
@ -33,11 +33,6 @@ class ReprFailDoctest(TerminalRepr):
|
||||||
self.reprlocation.toterminal(tw)
|
self.reprlocation.toterminal(tw)
|
||||||
|
|
||||||
class DoctestItem(pytest.Item):
|
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):
|
def repr_failure(self, excinfo):
|
||||||
if excinfo.errisinstance(py.std.doctest.DocTestFailure):
|
if excinfo.errisinstance(py.std.doctest.DocTestFailure):
|
||||||
doctestfailure = excinfo.value
|
doctestfailure = excinfo.value
|
||||||
|
@ -67,13 +62,13 @@ class DoctestItem(pytest.Item):
|
||||||
def reportinfo(self):
|
def reportinfo(self):
|
||||||
return self.fspath, None, "[doctest]"
|
return self.fspath, None, "[doctest]"
|
||||||
|
|
||||||
class DoctestTextfile(DoctestItem):
|
class DoctestTextfile(DoctestItem, pytest.File):
|
||||||
def runtest(self):
|
def runtest(self):
|
||||||
failed, tot = py.std.doctest.testfile(
|
failed, tot = py.std.doctest.testfile(
|
||||||
str(self.fspath), module_relative=False,
|
str(self.fspath), module_relative=False,
|
||||||
raise_on_error=True, verbose=0)
|
raise_on_error=True, verbose=0)
|
||||||
|
|
||||||
class DoctestModule(DoctestItem):
|
class DoctestModule(DoctestItem, pytest.File):
|
||||||
def runtest(self):
|
def runtest(self):
|
||||||
module = self.fspath.pyimport()
|
module = self.fspath.pyimport()
|
||||||
failed, tot = py.std.doctest.testmod(
|
failed, tot = py.std.doctest.testmod(
|
||||||
|
|
|
@ -482,6 +482,7 @@ class Session(FSCollector):
|
||||||
resultnodes = []
|
resultnodes = []
|
||||||
for node in matching:
|
for node in matching:
|
||||||
if isinstance(node, pytest.Item):
|
if isinstance(node, pytest.Item):
|
||||||
|
if not names:
|
||||||
resultnodes.append(node)
|
resultnodes.append(node)
|
||||||
continue
|
continue
|
||||||
assert isinstance(node, pytest.Collector)
|
assert isinstance(node, pytest.Collector)
|
||||||
|
@ -508,5 +509,3 @@ class Session(FSCollector):
|
||||||
for x in self.genitems(subnode):
|
for x in self.genitems(subnode):
|
||||||
yield x
|
yield x
|
||||||
node.ihook.pytest_collectreport(report=rep)
|
node.ihook.pytest_collectreport(report=rep)
|
||||||
|
|
||||||
Session = Session
|
|
||||||
|
|
|
@ -372,3 +372,22 @@ class TestInvocationVariants:
|
||||||
""")
|
""")
|
||||||
reprec = testdir.inline_run(testpath)
|
reprec = testdir.inline_run(testpath)
|
||||||
reprec.assertoutcome(passed=1)
|
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*",
|
||||||
|
])
|
||||||
|
|
||||||
|
|
|
@ -472,10 +472,6 @@ 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 getargnode(collection, arg):
|
|
||||||
argpath = arg.relto(collection.fspath)
|
|
||||||
return collection.perform_collect([argpath], genitems=False)[0]
|
|
||||||
|
|
||||||
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")
|
||||||
|
@ -552,3 +548,43 @@ class Test_genitems:
|
||||||
s = items[0].getmodpath(stopatmodule=False)
|
s = items[0].getmodpath(stopatmodule=False)
|
||||||
assert s.endswith("test_example_items1.testone")
|
assert s.endswith("test_example_items1.testone")
|
||||||
print(s)
|
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*",
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue