Skip to content

Commit

Permalink
capture: copy encoding and errors from from sys.stdout, if available
Browse files Browse the repository at this point in the history
  • Loading branch information
jszakmeister committed Nov 28, 2015
1 parent a02d4bf commit a8723ec
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions nose/plugins/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a8723ec

Please # to comment.