diff --git a/backend/tests/query_test/data_test.py b/backend/tests/query_test/data_test.py index e72f7e49..0b7f03cd 100644 --- a/backend/tests/query_test/data_test.py +++ b/backend/tests/query_test/data_test.py @@ -1,8 +1,8 @@ -import asyncio from datetime import date, datetime import os from uuid import uuid4 +import uvloop import pytest import pytest_asyncio from sqlalchemy import Engine, create_engine, text @@ -18,6 +18,7 @@ CLASS_TYPE, CLASSIFICATION_TABLE, ) + from tests.test_util import Fixture from store.conn import get_conn from store.store import Store @@ -29,12 +30,10 @@ ) -@pytest.fixture(scope="session", autouse=True) -def event_loop(): - """Necessary for async tests with module-scoped fixtures""" - loop = asyncio.get_event_loop() - yield loop - loop.close() +@pytest.fixture(scope="module") +def event_loop_policy(): + return uvloop.EventLoopPolicy() + @pytest.fixture(scope="module") @@ -85,7 +84,6 @@ async def new_db_store(api_config: Config, admin_engine: Engine): drop_db = text(f"DROP DATABASE {db_name};") conn.execute(drop_db) - @pytest.mark.asyncio async def test_create_class(new_db_store: Store): async with get_conn(new_db_store) as conn: diff --git a/backend/tests/query_test/store_test.py b/backend/tests/query_test/store_test.py index 2326515a..5dca105d 100644 --- a/backend/tests/query_test/store_test.py +++ b/backend/tests/query_test/store_test.py @@ -10,6 +10,7 @@ from apiserver.env import Config, load_config +import uvloop from tests.test_util import Fixture, AsyncFixture from store.conn import get_conn from store.store import Store @@ -22,21 +23,15 @@ "Skipping store_test as QUERY_TEST is not set.", allow_module_level=True ) - -@pytest.fixture(scope="session", autouse=True) -def event_loop(): - """Necessary for async tests with module-scoped fixtures""" - loop = asyncio.get_event_loop() - yield loop - loop.close() - +@pytest.fixture(scope="module") +def event_loop_policy(): + return uvloop.EventLoopPolicy() @pytest.fixture(scope="module") def api_config() -> Fixture[Config]: test_config_path = res_path.joinpath("querytestenv.toml") yield load_config(test_config_path) - @pytest_asyncio.fixture(scope="module") async def local_store(api_config: Config): # each module makes its own database @@ -48,7 +43,7 @@ async def local_store(api_config: Config): yield store -@pytest_asyncio.fixture +@pytest_asyncio.fixture(scope="module") async def setup_table(local_store: Store) -> AsyncFixture[str]: table_name = f"table_{randint(0, 100000)}" async with get_conn(local_store) as conn: @@ -72,7 +67,7 @@ async def setup_table(local_store: Store) -> AsyncFixture[str]: await conn.execute(query) -@pytest.mark.asyncio +@pytest.mark.asyncio(scope="module") async def test_insert(local_store: Store, setup_table: LiteralString): row: LiteralDict = {"first": 3, "second": "some", "third": "other"} async with get_conn(local_store) as conn: