From f55ded20a951988391d7f2877bc94e648a014948 Mon Sep 17 00:00:00 2001 From: Vincent Barbaresi Date: Tue, 16 Oct 2018 14:46:38 +0200 Subject: [PATCH 1/2] fix #3533: properly escape raw XML object Using string formatting with the raw escaped object lead to string evaluation "" Format the unescaped string first, then use the XML escape method as a last step. --- src/_pytest/junitxml.py | 8 +++++--- testing/test_junitxml.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/_pytest/junitxml.py b/src/_pytest/junitxml.py index ac00c772a1a..a39c94c1394 100644 --- a/src/_pytest/junitxml.py +++ b/src/_pytest/junitxml.py @@ -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) diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index 29d3f7f6ec1..079b01f3201 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -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") From d72154acda1e3f14ce6d531b5e4f54aff9e9a5f4 Mon Sep 17 00:00:00 2001 From: Vincent Barbaresi Date: Tue, 16 Oct 2018 15:01:07 +0200 Subject: [PATCH 2/2] add changelog for #3533 --- changelog/3533.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/3533.bugfix.rst diff --git a/changelog/3533.bugfix.rst b/changelog/3533.bugfix.rst new file mode 100644 index 00000000000..89f13645860 --- /dev/null +++ b/changelog/3533.bugfix.rst @@ -0,0 +1 @@ +Fix unescaped XML raw objects in JUnit report for skipped tests