diff options
author | Matt Chisholm <matt@theory.org> | 2013-02-18 20:34:04 +0100 |
---|---|---|
committer | John Szakmeister <john@szakmeister.net> | 2015-11-28 05:47:09 -0500 |
commit | a02d4bff78f19f9a5b94e08434f4019b4def0591 (patch) | |
tree | ab077a8b92b724522827ab176800ab63eff65725 | |
parent | 5b02f5a32e5fb13471d497bfd635c328ac32f146 (diff) | |
download | nose-a02d4bff78f19f9a5b94e08434f4019b4def0591.tar.gz |
fake stdout should always have encoding attribute
Some programs expect this attribute, and use it to encode strings before writing to stdout. If it's not there, they fail with an AttributeError.
-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() |