Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue469: add fix junit double colon split issue #1431

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

*

*
* Fix (`#469`_): junit parses report.nodeid incorrectly, when params contain
``::``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a "Thanks @tomviner" here. 😁


*

Expand Down Expand Up @@ -102,6 +103,7 @@

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

.. _#469: https://github.com/pytest-dev/pytest/issues/469
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this is the first time we are formatting the changelog like this, but I think this link would be better placed above the 2.9.0 header line, so the link targets reside at the bottom of their respective version headers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved in #1432 plus a couple of comments on the changelog.

.. _#1422: https://github.com/pytest-dev/pytest/issues/1422
.. _#1379: https://github.com/pytest-dev/pytest/issues/1379
.. _#1366: https://github.com/pytest-dev/pytest/issues/1366
Expand Down
17 changes: 14 additions & 3 deletions _pytest/junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class Junit(py.xml.Namespace):
del _legal_ranges
del _legal_xml_re

_py_ext_re = re.compile(r"\.py$")


def bin_xml_escape(arg):
def repl(matchobj):
Expand Down Expand Up @@ -89,7 +91,7 @@ def make_properties_node(self):

def record_testreport(self, testreport):
assert not self.testcase
names = mangle_testnames(testreport.nodeid.split("::"))
names = mangle_test_address(testreport.nodeid)
classnames = names[:-1]
if self.xml.prefix:
classnames.insert(0, self.xml.prefix)
Expand Down Expand Up @@ -235,9 +237,18 @@ def pytest_unconfigure(config):
config.pluginmanager.unregister(xml)


def mangle_testnames(names):
names = [x.replace(".py", "") for x in names if x != '()']
def mangle_test_address(address):
path, possible_open_bracket, params = address.partition('[')
names = path.split("::")
try:
names.remove('()')
except ValueError:
pass
# convert file path to dotted path
names[0] = names[0].replace("/", '.')
names[0] = _py_ext_re.sub("", names[0])
# put any params back
names[-1] += possible_open_bracket + params
return names


Expand Down
25 changes: 20 additions & 5 deletions testing/test_junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,12 @@ def test_function(arg):
assert "hello-stderr" in systemout.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"]
def test_mangle_test_address():
from _pytest.junitxml import mangle_test_address
address = '::'.join(
["a/my.py.thing.py", "Class", "()", "method", "[a-1-::]"])
newnames = mangle_test_address(address)
assert newnames == ["a.my.py.thing", "Class", "method", "[a-1-::]"]


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


def test_double_colon_split_issue469(testdir):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please also add another integration test, this time using a test method instead of a test function? Just to be safe. 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I originally wrote one, but changed by mind!

Added in #1432

testdir.makepyfile("""
import pytest
@pytest.mark.parametrize('param', ["double::colon"])
def test_func(param):
pass
""")
result, dom = runandparse(testdir)
assert result.ret == 0
node = dom.find_first_by_tag("testcase")
node.assert_attr(classname="test_double_colon_split_issue469")
node.assert_attr(name='test_func[double::colon]')


def test_unicode_issue368(testdir):
path = testdir.tmpdir.join("test.xml")
log = LogXML(str(path), None)
Expand Down