From: Brett Cannon Date: Fri, 29 Oct 2010 22:47:04 +0000 (+0000) Subject: Properly close a test file in test_cprofile. X-Git-Tag: v3.2a4~282 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5ede149342983531629c5fcf20982008542fae02;p=thirdparty%2FPython%2Fcpython.git Properly close a test file in test_cprofile. --- diff --git a/Lib/test/test_cprofile.py b/Lib/test/test_cprofile.py index 4586b36deb25..d7f9d7244d50 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():