refine classname normalization for junit-xml

--HG--
branch : trunk
This commit is contained in:
holger krekel 2010-01-12 01:35:50 +01:00
parent 3296939eda
commit 8d9e0712be
2 changed files with 17 additions and 2 deletions

View File

@ -35,7 +35,7 @@ class LogXML(object):
def _opentestcase(self, report):
node = report.item
d = {'time': self._durations.pop(report.item, "0")}
names = [x.replace(".py", "") for x in node.listnames()]
names = [x.replace(".py", "") for x in node.listnames() if x != "()"]
d['classname'] = ".".join(names[:-1])
d['name'] = names[-1]
attrs = ['%s="%s"' % item for item in sorted(d.items())]
@ -61,7 +61,7 @@ class LogXML(object):
def _opentestcase_collectfailure(self, report):
node = report.collector
d = {'time': '???'}
names = [x.replace(".py", "") for x in node.listnames()]
names = [x.replace(".py", "") for x in node.listnames() if x != "()"]
d['classname'] = ".".join(names[:-1])
d['name'] = names[-1]
attrs = ['%s="%s"' % item for item in sorted(d.items())]

View File

@ -49,6 +49,21 @@ class TestPython:
assert_attr(fnode, message="test setup failure")
assert "ValueError" in fnode.toxml()
def test_classname_instance(self, testdir):
testdir.makepyfile("""
class TestClass:
def test_method(self):
assert 0
""")
result, dom = runandparse(testdir)
assert result.ret
node = dom.getElementsByTagName("testsuite")[0]
assert_attr(node, failures=1)
tnode = node.getElementsByTagName("testcase")[0]
assert_attr(tnode,
classname="test_classname_instance.test_classname_instance.TestClass",
name="test_method")
def test_internal_error(self, testdir):
testdir.makeconftest("def pytest_runtest_protocol(): 0 / 0")
testdir.makepyfile("def test_function(): pass")