]> granicus.if.org Git - python/commitdiff
Issue #12400: test_cprofile now restores correctly the previous sys.stderr
authorVictor Stinner <victor.stinner@haypocalc.com>
Wed, 29 Jun 2011 22:00:45 +0000 (00:00 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Wed, 29 Jun 2011 22:00:45 +0000 (00:00 +0200)
Copy sys.stderr before replacing it, instead of using sys.__stderr__

Lib/test/test_cprofile.py

index ae17c2b69486a15aaba6e8ae655d578fed4b8477..56766682b3ccfecfb4ca2c1074b1bf6173dde2f6 100644 (file)
@@ -18,16 +18,19 @@ class CProfileTest(ProfileTest):
     def test_bad_counter_during_dealloc(self):
         import _lsprof
         # Must use a file as StringIO doesn't trigger the bug.
-        with open(TESTFN, 'w') as file:
-            sys.stderr = file
-            try:
-                obj = _lsprof.Profiler(lambda: int)
-                obj.enable()
-                obj = _lsprof.Profiler(1)
-                obj.disable()
-            finally:
-                sys.stderr = sys.__stderr__
-        unlink(TESTFN)
+        orig_stderr = sys.stderr
+        try:
+            with open(TESTFN, 'w') as file:
+                sys.stderr = file
+                try:
+                    obj = _lsprof.Profiler(lambda: int)
+                    obj.enable()
+                    obj = _lsprof.Profiler(1)
+                    obj.disable()
+                finally:
+                    sys.stderr = orig_stderr
+        finally:
+            unlink(TESTFN)
 
 
 def test_main():