]> granicus.if.org Git - python/commitdiff
Issue 10786: unittest.TextTestRunner default stream no longer bound at import time
authorMichael Foord <fuzzyman@voidspace.org.uk>
Thu, 30 Dec 2010 19:36:29 +0000 (19:36 +0000)
committerMichael Foord <fuzzyman@voidspace.org.uk>
Thu, 30 Dec 2010 19:36:29 +0000 (19:36 +0000)
Lib/unittest/runner.py
Lib/unittest/test/test_runner.py
Misc/NEWS

index c5e42587bd8cf6645ca31cb3c5fb8b6e2bb31628..10c4778434093ada7b20d05e2d2d0bd236cb25cb 100644 (file)
@@ -125,8 +125,10 @@ class TextTestRunner(object):
     """
     resultclass = TextTestResult
 
-    def __init__(self, stream=sys.stderr, descriptions=True, verbosity=1,
+    def __init__(self, stream=None, descriptions=True, verbosity=1,
                  failfast=False, buffer=False, resultclass=None, warnings=None):
+        if stream is None:
+            stream = sys.stderr
         self.stream = _WritelnDecorator(stream)
         self.descriptions = descriptions
         self.verbosity = verbosity
index 8f98a0242fd4ea321a35feeb70097988d8f850ff..8e95410e9ee63f70bcaac8482603c63339846460 100644 (file)
@@ -299,3 +299,20 @@ class Test_TextTestRunner(unittest.TestCase):
             self.assertEqual(out.count(msg), 3)
         for msg in [ae_msg, at_msg]:
             self.assertEqual(out.count(msg), 1)
+
+    def testStdErrLookedUpAtInstantiationTime(self):
+        # see issue 10786
+        old_stderr = sys.stderr
+        f = io.StringIO()
+        sys.stderr = f
+        try:
+            runner = unittest.TextTestRunner()
+            self.assertTrue(runner.stream.stream is f)
+        finally:
+            sys.stderr = old_stderr
+
+    def testSpecifiedStreamUsed(self):
+        # see issue 10786
+        f = io.StringIO()
+        runner = unittest.TextTestRunner(f)
+        self.assertTrue(runner.stream.stream is f)
index 111452a1041db6292c94bb9054503fa99a1d3017..9477594b26711a3a50f4b44fba109881a7fd28b5 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -20,6 +20,10 @@ Core and Builtins
 Library
 -------
 
+- Issue 10786: unittest.TextTestRunner default stream no longer bound at
+  import time. `sys.stderr` now looked up at instantiation time. Fix contributed
+  by Mark Roddy.
+
 - Issue 10753 - Characters ';','=' and ',' in the PATH_INFO environment
   variable won't be quoted when the URI is constructed by the wsgiref.util 's
   request_uri method. According to RFC 3986, these characters can be a part of