[Python-checkins] r79898 - in python/trunk/Lib/unittest: result.py test/test_result.py

michael.foord python-checkins at python.org
Thu Apr 8 01:04:22 CEST 2010


Author: michael.foord
Date: Thu Apr  8 01:04:22 2010
New Revision: 79898

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

Modified:
   python/trunk/Lib/unittest/result.py
   python/trunk/Lib/unittest/test/test_result.py

Modified: python/trunk/Lib/unittest/result.py
==============================================================================
--- python/trunk/Lib/unittest/result.py	(original)
+++ python/trunk/Lib/unittest/result.py	Thu Apr  8 01:04:22 2010
@@ -4,7 +4,7 @@
 import sys
 import traceback
 
-from cStringIO import StringIO
+from StringIO import StringIO
 
 from . import util
 from functools import wraps
@@ -46,8 +46,8 @@
         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 @@
         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
 

Modified: python/trunk/Lib/unittest/test/test_result.py
==============================================================================
--- python/trunk/Lib/unittest/test/test_result.py	(original)
+++ python/trunk/Lib/unittest/test/test_result.py	Thu Apr  8 01:04:22 2010
@@ -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 @@
         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 @@
 
         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


More information about the Python-checkins mailing list