From: Brett Cannon Date: Fri, 29 Oct 2010 23:27:39 +0000 (+0000) Subject: Fix file closing in test_http_cookiejar. X-Git-Tag: v3.2a4~277 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7f462fc8351ba4e02a12ff9a81df3e84324a4130;p=python Fix file closing in test_http_cookiejar. --- diff --git a/Lib/test/test_http_cookiejar.py b/Lib/test/test_http_cookiejar.py index c867bbc86e..fca67109a8 100644 --- a/Lib/test/test_http_cookiejar.py +++ b/Lib/test/test_http_cookiejar.py @@ -263,11 +263,11 @@ class FileCookieJarTests(unittest.TestCase): # Invalid contents of cookies file (eg. bad magic string) # causes a LoadError. try: - f = open(filename, "w") - f.write("oops\n") - for cookiejar_class in LWPCookieJar, MozillaCookieJar: - c = cookiejar_class() - self.assertRaises(LoadError, c.load, filename) + with open(filename, "w") as f: + f.write("oops\n") + for cookiejar_class in LWPCookieJar, MozillaCookieJar: + c = cookiejar_class() + self.assertRaises(LoadError, c.load, filename) finally: try: os.unlink(filename) except OSError: pass