Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fake stdout should always have encoding attribute #630

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nose/plugins/capture.py
Original file line number Diff line number Diff line change
@@ -109,6 +109,8 @@ 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
sys.stdout = self._buf

def end(self):
7 changes: 7 additions & 0 deletions unit_tests/test_capture_plugin.py
Original file line number Diff line number Diff line change
@@ -96,5 +96,12 @@ class Dummy:
err = sys.exc_info()
formatted = c.formatError(d, err)

def test_captured_stdout_has_encoding_attribute(self):
c = Capture()
c.start()
self.assertNotEqual(sys.stdout, sys.__stdout__)
self.assertTrue(hasattr(sys.stdout, 'encoding'))
c.end()

if __name__ == '__main__':
unittest.main()