JUnit XML: Escape error messages in setup/teardown (#10190)
Co-authored-by: Holesch, Simon (BSH) <simon.holesch@bshg.com>
This commit is contained in:
parent
433efaeaa9
commit
cc0092b9d8
1
AUTHORS
1
AUTHORS
|
@ -313,6 +313,7 @@ Seth Junot
|
||||||
Shantanu Jain
|
Shantanu Jain
|
||||||
Shubham Adep
|
Shubham Adep
|
||||||
Simon Gomizelj
|
Simon Gomizelj
|
||||||
|
Simon Holesch
|
||||||
Simon Kerr
|
Simon Kerr
|
||||||
Skylar Downes
|
Skylar Downes
|
||||||
Srinivas Reddy Thatiparthy
|
Srinivas Reddy Thatiparthy
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Invalid XML characters in setup or teardown error messages are now properly escaped for JUnit XML reports.
|
|
@ -231,7 +231,7 @@ class _NodeReporter:
|
||||||
msg = f'failed on teardown with "{reason}"'
|
msg = f'failed on teardown with "{reason}"'
|
||||||
else:
|
else:
|
||||||
msg = f'failed on setup with "{reason}"'
|
msg = f'failed on setup with "{reason}"'
|
||||||
self._add_simple("error", msg, str(report.longrepr))
|
self._add_simple("error", bin_xml_escape(msg), str(report.longrepr))
|
||||||
|
|
||||||
def append_skipped(self, report: TestReport) -> None:
|
def append_skipped(self, report: TestReport) -> None:
|
||||||
if hasattr(report, "wasxfail"):
|
if hasattr(report, "wasxfail"):
|
||||||
|
|
|
@ -1625,6 +1625,28 @@ def test_escaped_skipreason_issue3533(
|
||||||
snode.assert_attr(message="1 <> 2")
|
snode.assert_attr(message="1 <> 2")
|
||||||
|
|
||||||
|
|
||||||
|
def test_escaped_setup_teardown_error(
|
||||||
|
pytester: Pytester, run_and_parse: RunAndParse
|
||||||
|
) -> None:
|
||||||
|
pytester.makepyfile(
|
||||||
|
"""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def my_setup():
|
||||||
|
raise Exception("error: \033[31mred\033[m")
|
||||||
|
|
||||||
|
def test_esc(my_setup):
|
||||||
|
pass
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
_, dom = run_and_parse()
|
||||||
|
node = dom.find_first_by_tag("testcase")
|
||||||
|
snode = node.find_first_by_tag("error")
|
||||||
|
assert "#x1B[31mred#x1B[m" in snode["message"]
|
||||||
|
assert "#x1B[31mred#x1B[m" in snode.text
|
||||||
|
|
||||||
|
|
||||||
@parametrize_families
|
@parametrize_families
|
||||||
def test_logging_passing_tests_disabled_does_not_log_test_output(
|
def test_logging_passing_tests_disabled_does_not_log_test_output(
|
||||||
pytester: Pytester, run_and_parse: RunAndParse, xunit_family: str
|
pytester: Pytester, run_and_parse: RunAndParse, xunit_family: str
|
||||||
|
|
Loading…
Reference in New Issue