Skip to content

Commit cf81f94

Browse files
committed
Close test database fixtures explicitly
1 parent 555624d commit cf81f94

1 file changed

Lines changed: 28 additions & 10 deletions

File tree

test/conftest.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,17 @@ def init_db(path: Path) -> Path:
194194
Path.mkdir(path)
195195

196196
db_path = get_db_file_path(path)
197-
conn, _ = create_conn_db(db_path, read_only=False)
198-
init_tinysnb(conn)
199-
init_demo(conn)
200-
init_npy(conn)
201-
init_tensor(conn)
202-
init_long_str(conn)
203-
init_movie_serial(conn)
197+
conn, db = create_conn_db(db_path, read_only=False)
198+
try:
199+
init_tinysnb(conn)
200+
init_demo(conn)
201+
init_npy(conn)
202+
init_tensor(conn)
203+
init_long_str(conn)
204+
init_movie_serial(conn)
205+
finally:
206+
conn.close()
207+
db.close()
204208
return db_path
205209

206210

@@ -241,7 +245,12 @@ def conn_db_readonly(tmp_path: Path) -> ConnDB:
241245
@pytest.fixture
242246
def conn_db_readwrite(tmp_path: Path) -> ConnDB:
243247
"""Return a new writable connection and database."""
244-
return create_conn_db(init_db(tmp_path), read_only=False)
248+
conn, db = create_conn_db(init_db(tmp_path), read_only=False)
249+
try:
250+
yield conn, db
251+
finally:
252+
conn.close()
253+
db.close()
245254

246255

247256
@pytest.fixture
@@ -271,7 +280,12 @@ def async_connection_readwrite(tmp_path: Path) -> lb.AsyncConnection:
271280
@pytest.fixture
272281
def conn_db_empty(tmp_path: Path) -> ConnDB:
273282
"""Return a new empty connection and database."""
274-
return create_conn_db(get_db_file_path(tmp_path), read_only=False)
283+
conn, db = create_conn_db(get_db_file_path(tmp_path), read_only=False)
284+
try:
285+
yield conn, db
286+
finally:
287+
conn.close()
288+
db.close()
275289

276290

277291
@pytest.fixture
@@ -281,7 +295,11 @@ def conn_db_in_mem() -> ConnDB:
281295
database_path=":memory:", buffer_pool_size=_POOL_SIZE_, read_only=False
282296
)
283297
conn = lb.Connection(db, num_threads=4)
284-
return conn, db
298+
try:
299+
yield conn, db
300+
finally:
301+
conn.close()
302+
db.close()
285303

286304

287305
def pytest_sessionfinish(session: pytest.Session, exitstatus: int) -> None:

0 commit comments

Comments
 (0)