This is the weirdest thing ever and I've been spinning my wheels on it and I can't seem to figure it out. Ever since I enabled retain long output for Jenkins, it's been ignoring newlines on the blocks of output from my Pytest's captured stdout setup, but nowhere else! If you look at captured stdout, the newlines become literal characters and not actual newlines:
But if you look at any other section of the console output, it looks 100% fine:
This is blowing my mind, since the jUnit xml looks fine and if I run the pytest with the -s flag on any terminal or even on Jenkins it looks fine as well. Even if I switch off retain long output, it looks completely fine, but that truncates the console output which is less than ideal for what I'm trying to do.
Anybody know why this might be happening?
Thanks for reading this thread.
I had a similar problem using GitHub actions on a Windows runner.
The problem seemed to be that stdout is not going to a console so UTF-8 encoding isn't used by default. This means pytest gets a UnicodeEncodeError
when trying to write the output if there's any non CP-1252 characters, so it falls back to escaping everything including newlines.
The solution for me was to force UTF-8 by setting the environment variable PYTHONUTF8=1
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With