Skip to content

Commit 2853083

Browse files
committed
issue469: add fix junit double colon split issue
1 parent 055f1dc commit 2853083

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
*
77

8-
*
8+
* Fix (`#469`_): junit parses report.nodeid incorrectly, when params contain
9+
``::``.
910

1011
*
1112

@@ -102,6 +103,7 @@
102103

103104
.. _`traceback style docs`: https://pytest.org/latest/usage.html#modifying-python-traceback-printing
104105

106+
.. _#469: https://github.com/pytest-dev/pytest/issues/469
105107
.. _#1422: https://github.com/pytest-dev/pytest/issues/1422
106108
.. _#1379: https://github.com/pytest-dev/pytest/issues/1379
107109
.. _#1366: https://github.com/pytest-dev/pytest/issues/1366

_pytest/junitxml.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class Junit(py.xml.Namespace):
4646
del _legal_ranges
4747
del _legal_xml_re
4848

49+
_py_ext_re = re.compile(r"\.py$")
50+
4951

5052
def bin_xml_escape(arg):
5153
def repl(matchobj):
@@ -89,7 +91,7 @@ def make_properties_node(self):
8991

9092
def record_testreport(self, testreport):
9193
assert not self.testcase
92-
names = mangle_testnames(testreport.nodeid.split("::"))
94+
names = mangle_test_address(testreport.nodeid)
9395
classnames = names[:-1]
9496
if self.xml.prefix:
9597
classnames.insert(0, self.xml.prefix)
@@ -235,9 +237,18 @@ def pytest_unconfigure(config):
235237
config.pluginmanager.unregister(xml)
236238

237239

238-
def mangle_testnames(names):
239-
names = [x.replace(".py", "") for x in names if x != '()']
240+
def mangle_test_address(address):
241+
path, possible_open_bracket, params = address.partition('[')
242+
names = path.split("::")
243+
try:
244+
names.remove('()')
245+
except ValueError:
246+
pass
247+
# convert file path to dotted path
240248
names[0] = names[0].replace("/", '.')
249+
names[0] = _py_ext_re.sub("", names[0])
250+
# put any params back
251+
names[-1] += possible_open_bracket + params
241252
return names
242253

243254

testing/test_junitxml.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,12 @@ def test_function(arg):
449449
assert "hello-stderr" in systemout.toxml()
450450

451451

452-
def test_mangle_testnames():
453-
from _pytest.junitxml import mangle_testnames
454-
names = ["a/pything.py", "Class", "()", "method"]
455-
newnames = mangle_testnames(names)
456-
assert newnames == ["a.pything", "Class", "method"]
452+
def test_mangle_test_address():
453+
from _pytest.junitxml import mangle_test_address
454+
address = '::'.join(
455+
["a/my.py.thing.py", "Class", "()", "method", "[a-1-::]"])
456+
newnames = mangle_test_address(address)
457+
assert newnames == ["a.my.py.thing", "Class", "method", "[a-1-::]"]
457458

458459

459460
def test_dont_configure_on_slaves(tmpdir):
@@ -619,6 +620,20 @@ def test_func(char):
619620
node.assert_attr(name="test_func[#x00]")
620621

621622

623+
def test_double_colon_split_issue469(testdir):
624+
testdir.makepyfile("""
625+
import pytest
626+
@pytest.mark.parametrize('param', ["double::colon"])
627+
def test_func(param):
628+
pass
629+
""")
630+
result, dom = runandparse(testdir)
631+
assert result.ret == 0
632+
node = dom.find_first_by_tag("testcase")
633+
node.assert_attr(classname="test_double_colon_split_issue469")
634+
node.assert_attr(name='test_func[double::colon]')
635+
636+
622637
def test_unicode_issue368(testdir):
623638
path = testdir.tmpdir.join("test.xml")
624639
log = LogXML(str(path), None)

0 commit comments

Comments
 (0)