Skip to content
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

stdout capturing breaks sys.stdout.encoding #4389

Open
mgedmin opened this issue Nov 14, 2018 · 1 comment
Open

stdout capturing breaks sys.stdout.encoding #4389

mgedmin opened this issue Nov 14, 2018 · 1 comment
Labels
plugin: capture related to the capture builtin plugin type: bug problem that needs to be addressed

Comments

@mgedmin
Copy link
Contributor

mgedmin commented Nov 14, 2018

py.test by default replaces sys.stdout with something that captures test output, which is great! But the replacement stdout doesn't have a correct encoding attribute, and that can break the code under test.

(Prior to Python 3.6 sys.stdout.encoding is the only way to figure out the current OEM encoding on Windows, which you need if you have to decode the output of subprocesses. You can see what happens when people try to use py.test on such code here: mgedmin/check-manifest#92)

Here's a reproducible test case for Linux (note that you need to use Python 3.5 or older):

# test.py
import sys

def test_stdout_encoding():
    assert sys.stdout.encoding == 'ANSI_X3.4-1968'
LC_ALL=C py.test test.py -s     # succeeds
LC_ALL=C py.test test.py        # fails, sys.stdout.encoding is 'UTF8'
$ pip list|grep pytest
pytest                        3.9.3        
pytest-catchlog               1.2.2        /home/mg/src/pytest-catchlog
pytest-forked                 0.2          
pytest-xdist                  1.24.0       

This is similar to #2375, except I'm not using the capsys fixture.

@blueyed blueyed added type: bug problem that needs to be addressed plugin: capture related to the capture builtin plugin labels Nov 14, 2018
@blueyed blueyed self-assigned this Nov 15, 2018
blueyed added a commit to blueyed/pytest that referenced this issue Nov 15, 2018
@blueyed
Copy link
Contributor

blueyed commented Nov 15, 2018

Thanks for the report.
#4398 should fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: capture related to the capture builtin plugin type: bug problem that needs to be addressed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants