fix issue 144 - wrong classname in junitxml

This commit is contained in:
holger krekel 2012-05-22 17:18:04 +02:00
parent db8fbe7661
commit 0790f7a75f
4 changed files with 15 additions and 3 deletions

View File

@ -12,6 +12,7 @@ Changes between 2.2.3 and 2.2.4
- fix issue #141: switch from the deceased paste.pocoo.org to bpaste.net - fix issue #141: switch from the deceased paste.pocoo.org to bpaste.net
- fix issue #143: call unconfigure/sessionfinish always when - fix issue #143: call unconfigure/sessionfinish always when
configure/sessionstart where called configure/sessionstart where called
- fix issue #144: better mangle test ids to junitxml classnames
Changes between 2.2.2 and 2.2.3 Changes between 2.2.2 and 2.2.3
---------------------------------------- ----------------------------------------

View File

@ -81,6 +81,11 @@ def pytest_unconfigure(config):
config.pluginmanager.unregister(xml) config.pluginmanager.unregister(xml)
def mangle_testnames(names):
names = [x.replace(".py", "") for x in names if x != '()']
names[0] = names[0].replace("/", '.')
return names
class LogXML(object): class LogXML(object):
def __init__(self, logfile, prefix): def __init__(self, logfile, prefix):
logfile = os.path.expanduser(os.path.expandvars(logfile)) logfile = os.path.expanduser(os.path.expandvars(logfile))
@ -91,9 +96,7 @@ class LogXML(object):
self.failed = self.errors = 0 self.failed = self.errors = 0
def _opentestcase(self, report): def _opentestcase(self, report):
names = report.nodeid.split("::") names = mangle_testnames(report.nodeid.split("::"))
names[0] = names[0].replace("/", '.')
names = [x.replace(".py", "") for x in names if x != "()"]
classnames = names[:-1] classnames = names[:-1]
if self.prefix: if self.prefix:
classnames.insert(0, self.prefix) classnames.insert(0, self.prefix)

View File

@ -34,4 +34,5 @@ Changes between 2.2.3 and 2.2.4
- fix issue #141: switch from the deceased paste.pocoo.org to bpaste.net - fix issue #141: switch from the deceased paste.pocoo.org to bpaste.net
- fix issue #143: call unconfigure/sessionfinish always when - fix issue #143: call unconfigure/sessionfinish always when
configure/sessionstart where called configure/sessionstart where called
- fix issue #144: better mangle test ids to junitxml classnames

View File

@ -279,6 +279,13 @@ class TestPython:
if not sys.platform.startswith("java"): if not sys.platform.startswith("java"):
assert "hx" in fnode.toxml() assert "hx" in fnode.toxml()
def test_mangle_testnames():
from _pytest.junitxml import mangle_testnames
names = ["a/pything.py", "Class", "()", "method"]
newnames = mangle_testnames(names)
assert newnames == ["a.pything", "Class", "method"]
class TestNonPython: class TestNonPython:
def test_summing_simple(self, testdir): def test_summing_simple(self, testdir):
testdir.makeconftest(""" testdir.makeconftest("""