Skip to content

Commit b53aacb

Browse files
author
Erlend E. Aasland
committed
Address review: Explicitly close opened database files
1 parent 063878c commit b53aacb

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Lib/sqlite3/test/dbapi.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,26 +170,35 @@ def test_in_transaction_ro(self):
170170
with self.assertRaises(AttributeError):
171171
self.cx.in_transaction = True
172172

173+
174+
class OpenTests(unittest.TestCase):
175+
def tearDown(self):
176+
unlink(TESTFN)
177+
173178
def test_open_with_path_like_object(self):
174179
""" Checks that we can successfully connect to a database using an object that
175180
is PathLike, i.e. has __fspath__(). """
176-
self.addCleanup(unlink, TESTFN)
177181
class Path:
178182
def __fspath__(self):
179183
return TESTFN
180184
path = Path()
181185
with sqlite.connect(path) as cx:
182186
cx.execute('create table test(id integer)')
187+
cx.close()
183188

184189
def test_open_uri(self):
185-
self.addCleanup(unlink, TESTFN)
186190
with sqlite.connect(TESTFN) as cx:
187191
cx.execute('create table test(id integer)')
192+
cx.close()
193+
188194
with sqlite.connect('file:' + TESTFN, uri=True) as cx:
189195
cx.execute('insert into test(id) values(0)')
196+
cx.close()
197+
190198
with sqlite.connect('file:' + TESTFN + '?mode=ro', uri=True) as cx:
191199
with self.assertRaises(sqlite.OperationalError):
192200
cx.execute('insert into test(id) values(1)')
201+
cx.close()
193202

194203

195204
class CursorTests(unittest.TestCase):
@@ -942,6 +951,7 @@ def suite():
942951
CursorTests,
943952
ExtensionTests,
944953
ModuleTests,
954+
OpenTests,
945955
SqliteOnConflictTests,
946956
ThreadTests,
947957
]

Lib/sqlite3/test/hooks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ def trace(statement):
259259
cur.execute(queries[0])
260260
con2.execute("create table bar(x)")
261261
cur.execute(queries[1])
262+
con1.close()
263+
con2.close()
262264
self.assertEqual(traced_statements, queries)
263265

264266

0 commit comments

Comments
 (0)