]> granicus.if.org Git - python/commitdiff
bpo-33752: Fix a file leak in test_dbm. (GH-7376)
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 5 Jun 2018 13:03:00 +0000 (16:03 +0300)
committerGitHub <noreply@github.com>
Tue, 5 Jun 2018 13:03:00 +0000 (16:03 +0300)
With addCleanup() f.close() was executed after tearDown().

Lib/test/test_dbm.py

index 78c32c4c93d35c377d4fe85ac686a74a86724f5f..1884b5c683efda1b35338c4bdea2d98face32785 100644 (file)
@@ -75,10 +75,8 @@ class AnyDBMTestCase:
     def test_anydbm_creation_n_file_exists_with_invalid_contents(self):
         # create an empty file
         test.support.create_empty_file(_fname)
-
-        f = dbm.open(_fname, 'n')
-        self.addCleanup(f.close)
-        self.assertEqual(len(f), 0)
+        with dbm.open(_fname, 'n') as f:
+            self.assertEqual(len(f), 0)
 
     def test_anydbm_modification(self):
         self.init_db()