summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Szakmeister <john@szakmeister.net>2015-11-28 05:51:40 -0500
committerJohn Szakmeister <john@szakmeister.net>2015-11-28 07:13:51 -0500
commita8723ecfcf74105db2caabf1d2a4c614fd942396 (patch)
tree2ea7842b3175f501242f55db85518da99976fb28
parenta02d4bff78f19f9a5b94e08434f4019b4def0591 (diff)
downloadnose-a8723ecfcf74105db2caabf1d2a4c614fd942396.tar.gz
capture: copy encoding and errors from from sys.stdout, if available
-rw-r--r--nose/plugins/capture.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/nose/plugins/capture.py b/nose/plugins/capture.py
index 5d26f26..c81f21e 100644
--- a/nose/plugins/capture.py
+++ b/nose/plugins/capture.py
@@ -95,8 +95,15 @@ class Capture(Plugin):
def start(self):
self.stdout.append(sys.stdout)
self._buf = StringIO()
- if not hasattr(self._buf, 'encoding'):
- self._buf.encoding = sys.__stdout__.encoding
+ # Python 3's StringIO objects don't support setting encoding or errors
+ # directly and they're already set to None. So if the attributes
+ # already exist, skip adding them.
+ if (not hasattr(self._buf, 'encoding') and
+ hasattr(sys.stdout, 'encoding')):
+ self._buf.encoding = sys.stdout.encoding
+ if (not hasattr(self._buf, 'errors') and
+ hasattr(sys.stdout, 'errors')):
+ self._buf.errors = sys.stdout.errors
sys.stdout = self._buf
def end(self):