[py-svn] py-trunk commit bc6e7335cff1: add a terminalreporter.testid method
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Tue May 4 13:02:29 CEST 2010
# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview
# User holger krekel <holger at merlinux.eu>
# Date 1272969472 -7200
# Node ID bc6e7335cff11abb1d2a90cfe3cffcab89c47af7
# Parent a12ca0a0974c6b4207788c40f6e6c252aa3ecd49
add a terminalreporter.testid method
--- a/testing/plugin/test_pytest_terminal.py
+++ b/testing/plugin/test_pytest_terminal.py
@@ -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():
--- a/py/_plugin/pytest_terminal.py
+++ b/py/_plugin/pytest_terminal.py
@@ -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)
More information about the pytest-commit
mailing list