Skip to content

Commit

Permalink
Merge pull request #4167 from vbarbaresi/3533_junit_escape_skipped
Browse files Browse the repository at this point in the history
Fix #3533: properly escape raw XML object
  • Loading branch information
crazymerlyn authored Oct 16, 2018
2 parents 17655b5 + d72154a commit f858177
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/3533.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix unescaped XML raw objects in JUnit report for skipped tests
8 changes: 5 additions & 3 deletions src/_pytest/junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,14 @@ def append_skipped(self, report):
else:
filename, lineno, skipreason = report.longrepr
if skipreason.startswith("Skipped: "):
skipreason = bin_xml_escape(skipreason[9:])
skipreason = skipreason[9:]
details = "%s:%s: %s" % (filename, lineno, skipreason)

self.append(
Junit.skipped(
"%s:%s: %s" % (filename, lineno, skipreason),
bin_xml_escape(details),
type="pytest.skip",
message=skipreason,
message=bin_xml_escape(skipreason),
)
)
self.write_captured_output(report)
Expand Down
16 changes: 16 additions & 0 deletions testing/test_junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,3 +1222,19 @@ def test_func():
assert result.ret == 0
node = dom.find_first_by_tag("testsuite")
node.assert_attr(name=expected)


def test_escaped_skipreason_issue3533(testdir):
testdir.makepyfile(
"""
import pytest
@pytest.mark.skip(reason='1 <> 2')
def test_skip():
pass
"""
)
_, dom = runandparse(testdir)
node = dom.find_first_by_tag("testcase")
snode = node.find_first_by_tag("skipped")
assert "1 <> 2" in snode.text
snode.assert_attr(message="1 <> 2")

0 comments on commit f858177

Please sign in to comment.