diff options
author | John Szakmeister <john@szakmeister.net> | 2015-11-28 05:51:40 -0500 |
---|---|---|
committer | John Szakmeister <john@szakmeister.net> | 2015-11-28 07:13:51 -0500 |
commit | a8723ecfcf74105db2caabf1d2a4c614fd942396 (patch) | |
tree | 2ea7842b3175f501242f55db85518da99976fb28 | |
parent | a02d4bff78f19f9a5b94e08434f4019b4def0591 (diff) | |
download | nose-a8723ecfcf74105db2caabf1d2a4c614fd942396.tar.gz |
capture: copy encoding and errors from from sys.stdout, if available
-rw-r--r-- | nose/plugins/capture.py | 11 |
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): |