Conversation
Pygments-highlighted assertion diffs bake SGR codes into the longrepr. Strip them at the junitxml boundary so CI XML stays parseable without touching TerminalRepr (which must preserve user data containing escapes).
443cb6c to
c636f62
Compare
for more information, see https://pre-commit.ci
ege-arhan
left a comment
There was a problem hiding this comment.
_write_content (src/_pytest/junitxml.py:206-208 on head 6229b1e) still writes captured output via bin_xml_escape(content) without strip_ansi_escapes. Repro on pytest 9.1.1: a test printing "\x1b[31mred\x1b[0m" with --junitxml out.xml -o junit_logging=all leaves #x1B[31m...#x1B[0m inside <system-out> (verified by parsing the XML). The new test only covers failure details. Suggestion: apply strip_ansi_escapes(content) in _write_content too, or narrow the changelog if captured output is intentionally left verbatim.
_write_content still wrote captured stdout/stderr verbatim, so colored output left escape sequences in <system-out>/<system-err>. Also updates test_escaped_setup_teardown_error, which asserted the old escaped form. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @ege-arhan, you're right. |
Problem
Closes #12365. With Pygments installed and color enabled, assertion diffs under
-v/-vvembed ANSI SGR sequences intolongrepr. Those leak into--junitxmlas#x1B[...]fragments and break CI XML consumers.Fix
Strip SGR escape sequences at the junitxml write boundary (failure/error message and details) before
bin_xml_escape. This keeps TerminalRepr untouched for cases where user data intentionally contains escapes (whichsaferepralready renders as literal\x1btext).How tested
testing/test_junitxml.py::test_junitxml_strips_ansi_from_failure_details(with pygments,PY_COLORS=1,-vv).