[Python-checkins] r85945 - python/branches/py3k/Lib/test/test_cprofile.py

brett.cannon python-checkins at python.org
Sat Oct 30 00:47:05 CEST 2010


Author: brett.cannon
Date: Sat Oct 30 00:47:04 2010
New Revision: 85945

Log:
Properly close a test file in test_cprofile.

Modified:
   python/branches/py3k/Lib/test/test_cprofile.py

Modified: python/branches/py3k/Lib/test/test_cprofile.py
==============================================================================
--- python/branches/py3k/Lib/test/test_cprofile.py	(original)
+++ python/branches/py3k/Lib/test/test_cprofile.py	Sat Oct 30 00:47:04 2010
@@ -18,15 +18,16 @@
     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():


More information about the Python-checkins mailing list