22
33import sqlite3
44import unittest
5+ from contextlib import closing
56
67from test .support .os_helper import TESTFN , unlink
78
@@ -253,7 +254,7 @@ def test_dump_virtual_tables(self):
253254 def test_dump_virtual_table_data_roundtrip (self ):
254255 # gh-153729: a populated virtual table must round-trip through iterdump().
255256 self .addCleanup (unlink , TESTFN )
256- with sqlite3 .connect (TESTFN ) as src :
257+ with closing ( sqlite3 .connect (TESTFN ) ) as src :
257258 src .execute ("CREATE VIRTUAL TABLE test USING fts4(example)" )
258259 src .execute ("INSERT INTO test(example) VALUES('hello world')" )
259260 src .execute ("INSERT INTO test(example) VALUES('second row')" )
@@ -266,12 +267,12 @@ def test_dump_virtual_table_data_roundtrip(self):
266267
267268 restored_path = f"{ TESTFN } .restored"
268269 self .addCleanup (unlink , restored_path )
269- with sqlite3 .connect (restored_path ) as dst :
270+ with closing ( sqlite3 .connect (restored_path ) ) as dst :
270271 # Defensive mode blocks writable_schema writes to sqlite_master.
271272 dst .setconfig (sqlite3 .SQLITE_DBCONFIG_DEFENSIVE , False )
272273 dst .setconfig (sqlite3 .SQLITE_DBCONFIG_WRITABLE_SCHEMA , True )
273274 dst .executescript (script )
274- with sqlite3 .connect (restored_path ) as restored :
275+ with closing ( sqlite3 .connect (restored_path ) ) as restored :
275276 rows = restored .execute (
276277 "SELECT example FROM test ORDER BY docid"
277278 ).fetchall ()
0 commit comments