diff options
author | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-04-07 23:04:22 (GMT) |
---|---|---|
committer | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-04-07 23:04:22 (GMT) |
commit | f6ff26c486373dcb6c9ee2f4aae102202e89b722 (patch) | |
tree | cf9bae379f6535622a28b261b68e0291bfe38450 /Lib | |
parent | 9a39eccfe168a1ce86197aca0a5cd1de67aa1589 (diff) | |
download | cpython-f6ff26c486373dcb6c9ee2f4aae102202e89b722.zip cpython-f6ff26c486373dcb6c9ee2f4aae102202e89b722.tar.gz cpython-f6ff26c486373dcb6c9ee2f4aae102202e89b722.tar.bz2 |
unittest.result.TestResult does not create its buffers until they're used. It uses StringIO not cStringIO. Issue 8333.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/unittest/result.py | 9 | ||||
-rw-r--r-- | Lib/unittest/test/test_result.py | 8 |
2 files changed, 11 insertions, 6 deletions
diff --git a/Lib/unittest/result.py b/Lib/unittest/result.py index b9045f4..4b7cde6 100644 --- a/Lib/unittest/result.py +++ b/Lib/unittest/result.py @@ -4,7 +4,7 @@ import os import sys import traceback -from cStringIO import StringIO +from StringIO import StringIO from . import util from functools import wraps @@ -46,8 +46,8 @@ class TestResult(object): self.unexpectedSuccesses = [] self.shouldStop = False self.buffer = False - self._stdout_buffer = StringIO() - self._stderr_buffer = StringIO() + self._stdout_buffer = None + self._stderr_buffer = None self._original_stdout = sys.stdout self._original_stderr = sys.stderr self._mirrorOutput = False @@ -60,6 +60,9 @@ class TestResult(object): self.testsRun += 1 self._mirrorOutput = False if self.buffer: + if self._stderr_buffer is None: + self._stderr_buffer = StringIO() + self._stdout_buffer = StringIO() sys.stdout = self._stdout_buffer sys.stderr = self._stderr_buffer diff --git a/Lib/unittest/test/test_result.py b/Lib/unittest/test/test_result.py index c02b8ef..57ac549 100644 --- a/Lib/unittest/test/test_result.py +++ b/Lib/unittest/test/test_result.py @@ -1,6 +1,6 @@ import sys import textwrap -from cStringIO import StringIO, OutputType +from StringIO import StringIO from test import test_support import unittest @@ -24,6 +24,8 @@ class Test_TestResult(unittest.TestCase): self.assertEqual(len(result.failures), 0) self.assertEqual(result.testsRun, 0) self.assertEqual(result.shouldStop, False) + self.assertIsNone(result._stdout_buffer) + self.assertIsNone(result._stderr_buffer) # "This method can be called to signal that the set of tests being @@ -400,8 +402,8 @@ class TestOutputBuffering(unittest.TestCase): self.assertIsNot(real_out, sys.stdout) self.assertIsNot(real_err, sys.stderr) - self.assertIsInstance(sys.stdout, OutputType) - self.assertIsInstance(sys.stderr, OutputType) + self.assertIsInstance(sys.stdout, StringIO) + self.assertIsInstance(sys.stderr, StringIO) self.assertIsNot(sys.stdout, sys.stderr) out_stream = sys.stdout |