From ba9a76fdb33de948113b0e1908c9a8f95fde1627 Mon Sep 17 00:00:00 2001 From: Llandy Riveron Del Risco Date: Sat, 15 Jul 2017 16:15:26 +0200 Subject: [PATCH 1/2] Provides encoding attribute on CaptureIO Fix #2375 --- AUTHORS | 2 ++ _pytest/compat.py | 11 ++++++++++- changelog/2375.trivial | 1 + testing/test_capture.py | 9 +++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 changelog/2375.trivial diff --git a/AUTHORS b/AUTHORS index ca282870f..aa4474d09 100644 --- a/AUTHORS +++ b/AUTHORS @@ -92,6 +92,7 @@ Kevin Cox Kodi B. Arfer Lee Kamentsky Lev Maximov +Llandy Riveron Del Risco Loic Esteve Lukas Bednar Luke Murphy @@ -165,3 +166,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 269a23504..7fae7f252 100644 --- a/_pytest/compat.py +++ b/_pytest/compat.py @@ -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 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 8f6f2ccb2..2d0514e16 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -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): From da12c5234737b7afb2865dc0a2bd99ee138678d3 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 20 Jul 2017 21:05:40 -0300 Subject: [PATCH 2/2] Fix: do not load hypothesis during test_logging_initialized_in_test A recent release seem to have added a "logging" import to the top-level, which breaks test_logging_initialized_in_test --- _pytest/compat.py | 1 - testing/test_capture.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/_pytest/compat.py b/_pytest/compat.py index f79567cf1..e539f073d 100644 --- a/_pytest/compat.py +++ b/_pytest/compat.py @@ -284,7 +284,6 @@ if _PY2: # 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 diff --git a/testing/test_capture.py b/testing/test_capture.py index 4e1323e4b..38a92ca0e 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -355,7 +355,7 @@ class TestLoggingInteraction(object): """) result = testdir.runpytest_subprocess( p, "--traceconfig", - "-p", "no:capturelog") + "-p", "no:capturelog", "-p", "no:hypothesis", "-p", "no:hypothesispytest") assert result.ret != 0 result.stdout.fnmatch_lines([ "*hello432*",