add a terminalreporter.testid method
--HG-- branch : trunk
This commit is contained in:
parent
1a8b2838fa
commit
dd7fd97810
|
@ -128,6 +128,20 @@ class TerminalReporter:
|
|||
else:
|
||||
return "???", dict(red=True)
|
||||
|
||||
def gettestid(self, item, relative=True):
|
||||
fspath = item.fspath
|
||||
chain = [x for x in item.listchain() if x.fspath == fspath]
|
||||
chain = chain[1:]
|
||||
names = [x.name for x in chain if x.name != "()"]
|
||||
path = item.fspath
|
||||
if relative:
|
||||
relpath = path.relto(self.curdir)
|
||||
if relpath:
|
||||
path = relpath
|
||||
names.insert(0, str(path))
|
||||
return "::".join(names)
|
||||
|
||||
|
||||
def pytest_internalerror(self, excrepr):
|
||||
for line in str(excrepr).split("\n"):
|
||||
self.write_line("INTERNALERROR> " + line)
|
||||
|
|
|
@ -111,6 +111,22 @@ class TestTerminal:
|
|||
assert lines[1].endswith("xy.py .")
|
||||
assert lines[2] == "hello world"
|
||||
|
||||
def test_testid(self, testdir, linecomp):
|
||||
func,method = testdir.getitems("""
|
||||
def test_func():
|
||||
pass
|
||||
class TestClass:
|
||||
def test_method(self):
|
||||
pass
|
||||
""")
|
||||
tr = TerminalReporter(func.config, file=linecomp.stringio)
|
||||
id = tr.gettestid(func)
|
||||
assert id.endswith("test_testid.py::test_func")
|
||||
fspath = py.path.local(id.split("::")[0])
|
||||
assert fspath.check()
|
||||
id = tr.gettestid(method)
|
||||
assert id.endswith("test_testid.py::TestClass::test_method")
|
||||
|
||||
def test_looponfailreport(self, testdir, linecomp):
|
||||
modcol = testdir.getmodulecol("""
|
||||
def test_fail():
|
||||
|
|
Loading…
Reference in New Issue