From 5b10b9824780b2181158902067912ee9e7b04657 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 5 Mar 2019 10:06:26 +0200 Subject: bpo-22831: Use "with" to avoid possible fd leaks in tests (part 2). (GH-10929) --- Lib/test/test_os.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'Lib/test/test_os.py') diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 2340b848d9..746be1239b 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -1200,9 +1200,8 @@ class MakedirTests(unittest.TestCase): def test_exist_ok_existing_regular_file(self): base = support.TESTFN path = os.path.join(support.TESTFN, 'dir1') - f = open(path, 'w') - f.write('abc') - f.close() + with open(path, 'w') as f: + f.write('abc') self.assertRaises(OSError, os.makedirs, path) self.assertRaises(OSError, os.makedirs, path, exist_ok=False) self.assertRaises(OSError, os.makedirs, path, exist_ok=True) -- cgit v1.2.1