From bc4eecbbac030b585ae2d3847df05426aed0bc33 Mon Sep 17 00:00:00 2001 From: David Szotten Date: Mon, 22 Sep 2014 12:19:27 +0100 Subject: [PATCH] add `encoding` attr to DontReadFromInput required by https://docs.python.org/2/library/stdtypes.html#file.encoding and used e.g. by ipdb at _import_ time --HG-- branch : dontreadfrominput-encoding --- _pytest/capture.py | 3 +++ testing/test_capture.py | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/_pytest/capture.py b/_pytest/capture.py index c22c34bad..844c9dc0e 100644 --- a/_pytest/capture.py +++ b/_pytest/capture.py @@ -428,6 +428,9 @@ class DontReadFromInput: because in automated test runs it is better to crash than hang indefinitely. """ + + encoding = None + def read(self, *args): raise IOError("reading from stdin while output is captured") readline = read diff --git a/testing/test_capture.py b/testing/test_capture.py index 0175ec285..167f2e635 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -1025,6 +1025,18 @@ def test_error_attribute_issue555(testdir): reprec.assertoutcome(passed=1) +def test_dontreadfrominput_has_encoding(testdir): + testdir.makepyfile(""" + import sys + def test_capattr(): + # should not raise AttributeError + assert sys.stdout.encoding + assert sys.stderr.encoding + """) + reprec = testdir.inline_run() + reprec.assertoutcome(passed=1) + + def test_pickling_and_unpickling_enocded_file(): # See https://bitbucket.org/hpk42/pytest/pull-request/194 # pickle.loads() raises infinite recursion if