Skip to content

Commit ecbc107

Browse files
committed
Close async read-only fixture per test
1 parent cf81f94 commit ecbc107

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

test/conftest.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,15 @@ def conn_db_readwrite(tmp_path: Path) -> ConnDB:
255255

256256
@pytest.fixture
257257
def async_connection_readonly(tmp_path: Path) -> lb.AsyncConnection:
258-
"""Return a cached read-only async connection."""
259-
global _READONLY_ASYNC_CONNECTION_
260-
if _READONLY_ASYNC_CONNECTION_ is None:
261-
conn, db = create_conn_db(init_db(tmp_path), read_only=True)
262-
conn.close()
263-
_READONLY_ASYNC_CONNECTION_ = lb.AsyncConnection(db, max_threads_per_query=4)
264-
return _READONLY_ASYNC_CONNECTION_
258+
"""Return a read-only async connection."""
259+
conn, db = create_conn_db(init_db(tmp_path), read_only=True)
260+
conn.close()
261+
async_conn = lb.AsyncConnection(db, max_threads_per_query=4)
262+
try:
263+
yield async_conn
264+
finally:
265+
async_conn.close()
266+
db.close()
265267

266268

267269
@pytest.fixture

0 commit comments

Comments
 (0)