[Python-checkins] bpo-33752: Fix a file leak in test_dbm. (GH-7376)

Miss Islington (bot) webhook-mailer at python.org
Tue Jun 5 09:51:00 EDT 2018


https://github.com/python/cpython/commit/ffd72acc508bbc994812cefbfb9532d3be2ab737
commit: ffd72acc508bbc994812cefbfb9532d3be2ab737
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-06-05T06:50:56-07:00
summary:

bpo-33752: Fix a file leak in test_dbm. (GH-7376)


With addCleanup() f.close() was executed after tearDown().
(cherry picked from commit 6592d7fe11477f8f974d2d4a85c3382a1ad05217)

Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>

files:
M Lib/test/test_dbm.py

diff --git a/Lib/test/test_dbm.py b/Lib/test/test_dbm.py
index 78c32c4c93d3..1884b5c683ef 100644
--- a/Lib/test/test_dbm.py
+++ b/Lib/test/test_dbm.py
@@ -75,10 +75,8 @@ def test_anydbm_creation(self):
     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()



More information about the Python-checkins mailing list