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

Provides encoding attribute on CaptureIO #2578

Merged
merged 1 commit into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
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é
11 changes: 10 additions & 1 deletion _pytest/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,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

Expand Down
1 change: 1 addition & 0 deletions changelog/2375.trivial
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Provides encoding attribute on CaptureIO.
9 changes: 9 additions & 0 deletions testing/test_capture.py
Original file line number Diff line number Diff line change
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