Skip to content

Commit b586fc3

Browse files
committed
Fix test and avoid unclosed DB connection.
1 parent c4c8065 commit b586fc3

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Lib/test/test_dbm_sqlite3.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ def test_open_readonly_dir_fail_rw_missing_wal_shm(self):
158158
os.chmod(self.test_dir, stat.S_IREAD | stat.S_IEXEC)
159159

160160
with self.assertRaises(OSError):
161-
db = dbm_sqlite3.open(self.db_path, "w")
162-
db[b"newkey"] = b"newvalue"
163-
db.close()
161+
with dbm_sqlite3.open(self.db_path, "w") as db:
162+
db[b"newkey"] = b"newvalue"
163+
164164

165165
def test_open_readonly_dir_fail_rw_with_writable_db(self):
166166
os.chmod(self.db_path, stat.S_IREAD | stat.S_IWRITE)
@@ -170,9 +170,8 @@ def test_open_readonly_dir_fail_rw_with_writable_db(self):
170170
os.chmod(self.test_dir, stat.S_IREAD | stat.S_IEXEC)
171171

172172
with self.assertRaises(OSError):
173-
db = dbm_sqlite3.open(self.db_path, "w")
174-
db[b"newkey"] = b"newvalue"
175-
db.close()
173+
with dbm_sqlite3.open(self.db_path, "w") as db:
174+
db[b"newkey"] = b"newvalue"
176175

177176

178177
class ReadWrite(_SQLiteDbmTests):

0 commit comments

Comments
 (0)