diff options
-rw-r--r-- | nose/plugins/capture.py | 2 | ||||
-rw-r--r-- | unit_tests/test_capture_plugin.py | 7 |
2 files changed, 9 insertions, 0 deletions
diff --git a/nose/plugins/capture.py b/nose/plugins/capture.py index fa4e5dc..5d26f26 100644 --- a/nose/plugins/capture.py +++ b/nose/plugins/capture.py @@ -95,6 +95,8 @@ 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 sys.stdout = self._buf def end(self): diff --git a/unit_tests/test_capture_plugin.py b/unit_tests/test_capture_plugin.py index 2f721f0..edab7de 100644 --- a/unit_tests/test_capture_plugin.py +++ b/unit_tests/test_capture_plugin.py @@ -96,5 +96,12 @@ class TestCapturePlugin(unittest.TestCase): 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() |