Merge pull request #2578 from Llandy3d/2375

Provides encoding attribute on CaptureIO
This commit is contained in:
Floris Bruynooghe 2017-07-20 23:14:14 +02:00 committed by GitHub
commit 56e6b4b501
4 changed files with 22 additions and 1 deletions

View File

@ -93,6 +93,7 @@ Kevin Cox
Kodi B. Arfer
Lee Kamentsky
Lev Maximov
Llandy Riveron Del Risco
Loic Esteve
Lukas Bednar
Luke Murphy
@ -167,3 +168,4 @@ Vitaly Lashmanov
Vlad Dragos
Wouter van Ackooy
Xuecong Liao
Zoltán Máté

View File

@ -281,7 +281,16 @@ def _setup_collect_fakemodule():
if _PY2:
from py.io import TextIO as CaptureIO
# Without this the test_dupfile_on_textio will fail, otherwise CaptureIO could directly inherit from StringIO.
from py.io import TextIO
class CaptureIO(TextIO):
@property
def encoding(self):
return getattr(self, '_encoding', 'UTF-8')
else:
import io

1
changelog/2375.trivial Normal file
View File

@ -0,0 +1 @@
Provides encoding attribute on CaptureIO.

View File

@ -1040,6 +1040,15 @@ def test_capture_not_started_but_reset():
capsys.stop_capturing()
def test_using_capsys_fixture_works_with_sys_stdout_encoding(capsys):
test_text = 'test text'
print(test_text.encode(sys.stdout.encoding, 'replace'))
(out, err) = capsys.readouterr()
assert out
assert err == ''
@needsosdup
@pytest.mark.parametrize('use', [True, False])
def test_fdcapture_tmpfile_remains_the_same(tmpfile, use):