Don't use pytest_asyncio.fixture(scope="session") any more, refs #1959

Also got rid of the weird memory=False hack:

https://github.com/simonw/datasette/pull/1960#issuecomment-1354053151
This commit is contained in:
Simon Willison 2022-12-15 17:38:22 -08:00
commit d94d363ec0
3 changed files with 14 additions and 13 deletions

View file

@ -281,7 +281,7 @@ class Datasette:
raise raise
self.crossdb = crossdb self.crossdb = crossdb
self.nolock = nolock self.nolock = nolock
if memory or crossdb or (not self.files and memory is not False): if memory or crossdb or not self.files:
self.add_database( self.add_database(
Database(self, is_mutable=False, is_memory=True), name="_memory" Database(self, is_mutable=False, is_memory=True), name="_memory"
) )

View file

@ -25,18 +25,12 @@ UNDOCUMENTED_PERMISSIONS = {
} }
@pytest.fixture(scope="session") @pytest_asyncio.fixture
def event_loop():
return asyncio.get_event_loop()
@pytest_asyncio.fixture(scope="session")
async def ds_client(): async def ds_client():
from datasette.app import Datasette from datasette.app import Datasette
from .fixtures import METADATA, PLUGINS_DIR from .fixtures import METADATA, PLUGINS_DIR
ds = Datasette( ds = Datasette(
memory=False,
metadata=METADATA, metadata=METADATA,
plugins_dir=PLUGINS_DIR, plugins_dir=PLUGINS_DIR,
settings={ settings={
@ -51,12 +45,14 @@ async def ds_client():
from .fixtures import TABLES, TABLE_PARAMETERIZED_SQL from .fixtures import TABLES, TABLE_PARAMETERIZED_SQL
db = ds.add_memory_database("fixtures") db = ds.add_memory_database("fixtures")
ds.remove_database("_memory")
def prepare(conn): def prepare(conn):
conn.executescript(TABLES) if not conn.execute("select count(*) from sqlite_master").fetchone()[0]:
for sql, params in TABLE_PARAMETERIZED_SQL: conn.executescript(TABLES)
with conn: for sql, params in TABLE_PARAMETERIZED_SQL:
conn.execute(sql, params) with conn:
conn.execute(sql, params)
await db.execute_write_fn(prepare) await db.execute_write_fn(prepare)
return ds.client return ds.client

View file

@ -117,7 +117,12 @@ def actor_from_request(datasette, request):
def permission_allowed(datasette, actor, action): def permission_allowed(datasette, actor, action):
# Testing asyncio version of permission_allowed # Testing asyncio version of permission_allowed
async def inner(): async def inner():
assert 2 == (await datasette.get_database().execute("select 1 + 1")).first()[0] assert (
2
== (
await datasette.get_database("_internal").execute("select 1 + 1")
).first()[0]
)
if action == "this_is_allowed_async": if action == "this_is_allowed_async":
return True return True
elif action == "this_is_denied_async": elif action == "this_is_denied_async":