From a8723ecfcf74105db2caabf1d2a4c614fd942396 Mon Sep 17 00:00:00 2001 From: John Szakmeister Date: Sat, 28 Nov 2015 05:51:40 -0500 Subject: [PATCH] capture: copy encoding and errors from from sys.stdout, if available --- nose/plugins/capture.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/nose/plugins/capture.py b/nose/plugins/capture.py index 5d26f268..c81f21ec 100644 --- a/nose/plugins/capture.py +++ b/nose/plugins/capture.py @@ -95,8 +95,15 @@ def addCaptureToErr(self, ev, output): 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):