From: Benjamin Peterson Date: Sat, 20 Dec 2014 19:41:14 +0000 (-0600) Subject: explicitly close files (closes #23090) X-Git-Tag: v2.7.10rc1~258 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4e9dbfba217301b20f0891746ba81556858f6495;p=python explicitly close files (closes #23090) Patch by Brian Kearns. --- diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py index 07a2997ae2..61c7ba7498 100644 --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -2580,7 +2580,8 @@ Windows line endings first: >>> import tempfile, os >>> fn = tempfile.mktemp() - >>> open(fn, 'w').write('Test:\r\n\r\n >>> x = 1 + 1\r\n\r\nDone.\r\n') + >>> with open(fn, 'w') as f: + ... f.write('Test:\r\n\r\n >>> x = 1 + 1\r\n\r\nDone.\r\n') >>> doctest.testfile(fn, False) TestResults(failed=0, attempted=1) >>> os.remove(fn) @@ -2588,7 +2589,8 @@ Windows line endings first: And now *nix line endings: >>> fn = tempfile.mktemp() - >>> open(fn, 'w').write('Test:\n\n >>> x = 1 + 1\n\nDone.\n') + >>> with open(fn, 'w') as f: + ... f.write('Test:\n\n >>> x = 1 + 1\n\nDone.\n') >>> doctest.testfile(fn, False) TestResults(failed=0, attempted=1) >>> os.remove(fn)