summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFloris Bruynooghe <flub@devork.be>2017-07-20 23:14:14 +0200
committerGitHub <noreply@github.com>2017-07-20 23:14:14 +0200
commit56e6b4b501258393e5ee8921df2f2a55141b7712 (patch)
tree4d25e03c648402431df07ef4fa96b116f8500075
parentc92760dca8637251eb9e7b9ea4819b32bc0b8042 (diff)
parentba9a76fdb33de948113b0e1908c9a8f95fde1627 (diff)
downloadpytest-56e6b4b501258393e5ee8921df2f2a55141b7712.tar.gz
Merge pull request #2578 from Llandy3d/2375
Provides encoding attribute on CaptureIO
-rw-r--r--AUTHORS2
-rw-r--r--_pytest/compat.py11
-rw-r--r--changelog/2375.trivial1
-rw-r--r--testing/test_capture.py9
4 files changed, 22 insertions, 1 deletions
diff --git a/AUTHORS b/AUTHORS
index 105237d0d..d58cd3d2d 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -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é
diff --git a/_pytest/compat.py b/_pytest/compat.py
index cdca56387..f79567cf1 100644
--- a/_pytest/compat.py
+++ b/_pytest/compat.py
@@ -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
diff --git a/changelog/2375.trivial b/changelog/2375.trivial
new file mode 100644
index 000000000..a73ab6ccf
--- /dev/null
+++ b/changelog/2375.trivial
@@ -0,0 +1 @@
+Provides encoding attribute on CaptureIO.
diff --git a/testing/test_capture.py b/testing/test_capture.py
index 302a02d10..4e1323e4b 100644
--- a/testing/test_capture.py
+++ b/testing/test_capture.py
@@ -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):