summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2010-10-29 22:47:04 (GMT)
committerBrett Cannon <bcannon@gmail.com>2010-10-29 22:47:04 (GMT)
commit5ede149342983531629c5fcf20982008542fae02 (patch)
tree5968594e0c5907737444fe76c928d0f88a2c40bd
parent2d562f80811bdb947eaf85430bbb550c7e845419 (diff)
downloadcpython-5ede149342983531629c5fcf20982008542fae02.zip
cpython-5ede149342983531629c5fcf20982008542fae02.tar.gz
cpython-5ede149342983531629c5fcf20982008542fae02.tar.bz2
Properly close a test file in test_cprofile.
-rw-r--r--Lib/test/test_cprofile.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/Lib/test/test_cprofile.py b/Lib/test/test_cprofile.py
index 4586b36..d7f9d72 100644
--- a/Lib/test/test_cprofile.py
+++ b/Lib/test/test_cprofile.py
@@ -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():