From 8d9e0712beea04af534cd558128161ecabe7c43d Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 12 Jan 2010 01:35:50 +0100 Subject: [PATCH] refine classname normalization for junit-xml --HG-- branch : trunk --- py/plugin/pytest_logxml.py | 4 ++-- testing/plugin/test_pytest_logxml.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/py/plugin/pytest_logxml.py b/py/plugin/pytest_logxml.py index d744bcf59..68b3f740e 100644 --- a/py/plugin/pytest_logxml.py +++ b/py/plugin/pytest_logxml.py @@ -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())] diff --git a/testing/plugin/test_pytest_logxml.py b/testing/plugin/test_pytest_logxml.py index 2c2fb0afe..11ae74815 100644 --- a/testing/plugin/test_pytest_logxml.py +++ b/testing/plugin/test_pytest_logxml.py @@ -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")