Skip to content

Commit

Permalink
Provides encoding attribute on CaptureIO
Browse files Browse the repository at this point in the history
  • Loading branch information
Llandy3d committed Jul 16, 2017
1 parent 3578f4e commit 27f1486
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions AUTHORS
Expand Up @@ -92,6 +92,7 @@ Kevin Cox
Kodi B. Arfer
Lee Kamentsky
Lev Maximov
Llandy Riveron Del Risco
Loic Esteve
Lukas Bednar
Luke Murphy
Expand Down Expand Up @@ -165,3 +166,4 @@ Vitaly Lashmanov
Vlad Dragos
Wouter van Ackooy
Xuecong Liao
Zoltán Máté
13 changes: 12 additions & 1 deletion _pytest/compat.py
Expand Up @@ -283,7 +283,18 @@ def _setup_collect_fakemodule():


if _PY2:
from py.io import TextIO as CaptureIO
import io

class CaptureIO(io.StringIO):
def write(self, data):
if not isinstance(data, unicode):
data = unicode(data, getattr(self, '_encoding', 'UTF-8'), 'replace')
io.StringIO.write(self, data)

@property
def encoding(self):
return getattr(self, '_encoding', 'UTF-8')

else:
import io

Expand Down
1 change: 1 addition & 0 deletions changelog/2375.trivial
@@ -0,0 +1 @@
Provides encoding attribute on CaptureIO. Removed py.io dependency for CaptureIO.
9 changes: 9 additions & 0 deletions testing/test_capture.py
Expand Up @@ -1037,6 +1037,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):
Expand Down

0 comments on commit 27f1486

Please sign in to comment.