From 1335bcb8939e903a4a7680493624055faecc3da4 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Thu, 15 Dec 2022 19:33:14 -0800 Subject: [PATCH] Use my own global variable instead of scope=session Refs https://github.com/simonw/datasette/pull/1960#issuecomment-1354148139 --- tests/conftest.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index e122d0d9..197992c5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -24,12 +24,18 @@ UNDOCUMENTED_PERMISSIONS = { "no_match", } +_ds_client = None + @pytest_asyncio.fixture async def ds_client(): from datasette.app import Datasette from .fixtures import METADATA, PLUGINS_DIR + global _ds_client + if _ds_client is not None: + return _ds_client + ds = Datasette( metadata=METADATA, plugins_dir=PLUGINS_DIR, @@ -55,7 +61,8 @@ async def ds_client(): conn.execute(sql, params) await db.execute_write_fn(prepare) - return ds.client + _ds_client = ds.client + return _ds_client def pytest_report_header(config):