Anonymous avatar Anonymous committed a39bf38

unittest.result.TestResult does not create its buffers until they're used. It uses StringIO not cStringIO. Issue 8333.

Comments (0)

Files changed (2)


 import sys
 import traceback
-from cStringIO import StringIO
+from StringIO import StringIO
 from . import util
 from functools import wraps
         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
         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


 import sys
 import textwrap
-from cStringIO import StringIO, OutputType
+from StringIO import StringIO
 from test import test_support
 import unittest
         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
         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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.