]> granicus.if.org Git - python/commitdiff
Properly close a test file in test_cprofile.
authorBrett Cannon <bcannon@gmail.com>
Fri, 29 Oct 2010 22:47:04 +0000 (22:47 +0000)
committerBrett Cannon <bcannon@gmail.com>
Fri, 29 Oct 2010 22:47:04 +0000 (22:47 +0000)
Lib/test/test_cprofile.py

index 4586b36deb25b3d79578780f58029fd36793a310..d7f9d7244d5052229b051b3afa47af6c8249e87e 100644 (file)
@@ -18,15 +18,16 @@ class CProfileTest(ProfileTest):
     def test_bad_counter_during_dealloc(self):
         import _lsprof
         # Must use a file as StringIO doesn't trigger the bug.
-        sys.stderr = open(TESTFN, 'w')
-        try:
-            obj = _lsprof.Profiler(lambda: int)
-            obj.enable()
-            obj = _lsprof.Profiler(1)
-            obj.disable()
-        finally:
-            sys.stderr = sys.__stderr__
-            unlink(TESTFN)
+        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)
 
 
 def test_main():