Escape skip reason in junitxml (#11842)
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
This commit is contained in:
parent
2178ee86d7
commit
d71ef04f11
|
@ -0,0 +1 @@
|
|||
Properly escape the ``reason`` of a :ref:`skip <pytest.mark.skip ref>` mark when writing JUnit XML files.
|
|
@ -248,7 +248,9 @@ class _NodeReporter:
|
|||
skipreason = skipreason[9:]
|
||||
details = f"{filename}:{lineno}: {skipreason}"
|
||||
|
||||
skipped = ET.Element("skipped", type="pytest.skip", message=skipreason)
|
||||
skipped = ET.Element(
|
||||
"skipped", type="pytest.skip", message=bin_xml_escape(skipreason)
|
||||
)
|
||||
skipped.text = bin_xml_escape(details)
|
||||
self.append(skipped)
|
||||
self.write_captured_output(report)
|
||||
|
|
|
@ -1653,6 +1653,23 @@ def test_escaped_skipreason_issue3533(
|
|||
snode.assert_attr(message="1 <> 2")
|
||||
|
||||
|
||||
def test_bin_escaped_skipreason(pytester: Pytester, run_and_parse: RunAndParse) -> None:
|
||||
"""Escape special characters from mark.skip reason (#11842)."""
|
||||
pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
@pytest.mark.skip("\33[31;1mred\33[0m")
|
||||
def test_skip():
|
||||
pass
|
||||
"""
|
||||
)
|
||||
_, dom = run_and_parse()
|
||||
node = dom.find_first_by_tag("testcase")
|
||||
snode = node.find_first_by_tag("skipped")
|
||||
assert "#x1B[31;1mred#x1B[0m" in snode.text
|
||||
snode.assert_attr(message="#x1B[31;1mred#x1B[0m")
|
||||
|
||||
|
||||
def test_escaped_setup_teardown_error(
|
||||
pytester: Pytester, run_and_parse: RunAndParse
|
||||
) -> None:
|
||||
|
|
Loading…
Reference in New Issue