-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
ASCII color chars leaking into xml report file when using verbose flag #12365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks @ro-oliveira95! |
I investigated this, unfortunately it seems it is not simple to fix, or at least I cannot figure out a simple solution. #11661 was implemented so that it is generating the color codes directly as part of the exception message, which is represented just as a string. The JUnitXML plugin then cannot safely remove the color codes from the exception message before writing the XML, because at that point we cannot be sure the color codes in the message were included by pytest or by the code under testing -- for example a color-related library might be testing the strings they output (which include color codes), so stripping them away would definitely be a bad thing to do. The only solution I think (other than ugly workarounds like stripping color codes from junitxml based on a flag) is to refactor how error messages are produced, so instead of plain strings we can use better structures, for example we could instead of returning only |
Alright @nicoddemus, thanks for digging into this. Since the fix is not as simple as we'd like, I'll leave my first contribution for another time/issue =) |
Hello, I'd like to give this a go. I'll dig into this and see if I can come up with a quick workaround. While I'm at it, I'll also think of how I can do the refactoring like @nicoddemus suggested, and will proceed with it if I can't come up with a good workaround for this specific issue. |
I got curious (we had some output wit those escapes recently, not the first time). (I kind of remember to try and use "cdata" with same bad results) The most obvious options that came to my mind are:
|
Problem description
A bug was noticed when displaying failing tests on CI with the
-vv
flag: the ASCII color characters are being printed inside the detailed diff.The displayed output comes directly from xml file (generated with the
--junitxml
flag), which in fact carries the undesired characters as shown in the minimal example below. This happens only whenpygments
is also installed, with both-v
and-vv
flags.This undesired behavior was noticed in all 8.* versions but not in 7.4, so it probably was introduced in 8.0 together with the improved verbose diffs change (changelog).
Output of
pip list
pytest and operating system versions
uname -a
):Linux FLDEVWSV032 6.5.0-35-generic #35~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 7 09:00:52 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
3.10.2
8.0.0
,8.1.0
,8.2.1
Minimal example
test_foo.py
:Running it:
foo.xml
:For comparison, without having
pygments
installed the xml looks like this:If confirmed, I'd be happy to submit a PR fixing this.
The text was updated successfully, but these errors were encountered: