Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Jenkins captured stdout ignoring newlines on console output?

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:

captured stdout setup

But if you look at any other section of the console output, it looks 100% fine:

captured stderr setup

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.

like image 814
Eddie Rivas Avatar asked Nov 23 '22 05:11

Eddie Rivas


1 Answers

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.

like image 124
parched Avatar answered Nov 24 '22 17:11

parched