@@ -42,7 +42,7 @@ def pytest_collection_modifyitems(
4242 reason = "Known C-API backend failure"
4343 for item in items :
4444 if item .nodeid in CAPI_XFAILS :
45- item .add_marker (pytest .mark .xfail (reason = reason , strict = True ))
45+ item .add_marker (pytest .mark .xfail (reason = reason , strict = True , run = False ))
4646
4747
4848def init_npy (conn : lb .Connection ) -> None :
@@ -208,6 +208,20 @@ def init_db(path: Path) -> Path:
208208_READONLY_ASYNC_CONNECTION_ : lb .AsyncConnection | None = None
209209
210210
211+ def _close_cached_readonly_state () -> None :
212+ global _READONLY_ASYNC_CONNECTION_ , _READONLY_CONN_DB_
213+
214+ if _READONLY_ASYNC_CONNECTION_ is not None :
215+ _READONLY_ASYNC_CONNECTION_ .close ()
216+ _READONLY_ASYNC_CONNECTION_ = None
217+
218+ if _READONLY_CONN_DB_ is not None :
219+ conn , db = _READONLY_CONN_DB_
220+ conn .close ()
221+ db .close ()
222+ _READONLY_CONN_DB_ = None
223+
224+
211225def create_conn_db (path : Path , * , read_only : bool ) -> ConnDB :
212226 """Return a new connection and database."""
213227 db = lb .Database (path , buffer_pool_size = _POOL_SIZE_ , read_only = read_only )
@@ -246,7 +260,12 @@ def async_connection_readwrite(tmp_path: Path) -> lb.AsyncConnection:
246260 """Return a writeable async connection."""
247261 conn , db = create_conn_db (init_db (tmp_path ), read_only = False )
248262 conn .close ()
249- return lb .AsyncConnection (db , max_threads_per_query = 4 )
263+ async_conn = lb .AsyncConnection (db , max_threads_per_query = 4 )
264+ try :
265+ yield async_conn
266+ finally :
267+ async_conn .close ()
268+ db .close ()
250269
251270
252271@pytest .fixture
@@ -265,6 +284,11 @@ def conn_db_in_mem() -> ConnDB:
265284 return conn , db
266285
267286
287+ def pytest_sessionfinish (session : pytest .Session , exitstatus : int ) -> None :
288+ del session , exitstatus
289+ _close_cached_readonly_state ()
290+
291+
268292@pytest .fixture
269293def build_dir () -> Path :
270294 return python_build_dir
0 commit comments