[Python-checkins] r61622 - python/trunk/Lib/test/test_print.py

eric.smith python-checkins at python.org
Wed Mar 19 13:09:56 CET 2008


Author: eric.smith
Date: Wed Mar 19 13:09:55 2008
New Revision: 61622

Modified:
   python/trunk/Lib/test/test_print.py
Log:
Use test.test_support.captured_stdout instead of a custom contextmanager.
Thanks Nick Coghlan.

Modified: python/trunk/Lib/test/test_print.py
==============================================================================
--- python/trunk/Lib/test/test_print.py	(original)
+++ python/trunk/Lib/test/test_print.py	Wed Mar 19 13:09:55 2008
@@ -14,8 +14,6 @@
     # 2.x
     from StringIO import StringIO
 
-from contextlib import contextmanager
-
 NotDefined = object()
 
 # A dispatch table all 8 combinations of providing
@@ -42,15 +40,6 @@
      lambda args, sep, end, file: print(sep=sep, end=end, file=file, *args),
     }
 
- at contextmanager
-def stdout_redirected(new_stdout):
-    save_stdout = sys.stdout
-    sys.stdout = new_stdout
-    try:
-        yield None
-    finally:
-        sys.stdout = save_stdout
-
 # Class used to test __str__ and print
 class ClassWith__str__:
     def __init__(self, x):
@@ -71,8 +60,7 @@
                        end is not NotDefined,
                        file is not NotDefined)]
 
-        t = StringIO()
-        with stdout_redirected(t):
+        with test_support.captured_stdout() as t:
             fn(args, sep, end, file)
 
         self.assertEqual(t.getvalue(), expected)


More information about the Python-checkins mailing list