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: https://github.com/mgedmin/check-manifest/pull/92)
Here's a reproducible test case for Linux (note that you need to use Python 3.5 or older):
py.test by default replaces
sys.stdout
with something that captures test output, which is great! But the replacement stdout doesn't have a correctencoding
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: https://github.com/mgedmin/check-manifest/pull/92)Here's a reproducible test case for Linux (note that you need to use Python 3.5 or older):
This is similar to #2375, except I'm not using the
capsys
fixture.