Skip to content

Commit 12f467b

Browse files
committed
module scope
1 parent 3978eab commit 12f467b

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

services/web/server/tests/unit/with_dbs/04/studies_dispatcher/test_studies_dispatcher_rest_nih.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
# pylint: disable=unused-argument
55
# pylint: disable=unused-variable
66

7-
from collections.abc import AsyncIterator
8-
from contextlib import AsyncExitStack
7+
from collections.abc import Iterator
8+
from contextlib import ExitStack
99

1010
import pytest
11+
import sqlalchemy as sa
1112
from aiohttp.test_utils import TestClient, TestServer
1213
from common_library.json_serialization import json_dumps
1314
from common_library.serialization import model_dump_with_secrets
@@ -19,7 +20,7 @@
1920
random_service_meta_data,
2021
)
2122
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
22-
from pytest_simcore.helpers.postgres_tools import insert_and_get_row_lifespan
23+
from pytest_simcore.helpers.postgres_tools import sync_insert_and_get_row_lifespan
2324
from pytest_simcore.helpers.typing_env import EnvVarsDict
2425
from servicelib.aiohttp import status
2526
from settings_library.rabbit import RabbitSettings
@@ -34,7 +35,6 @@
3435
from simcore_service_webserver.studies_dispatcher._controller.rest.nih_schemas import (
3536
ServiceGet,
3637
)
37-
from sqlalchemy.ext.asyncio import AsyncEngine
3838
from yarl import URL
3939

4040
pytest_simcore_core_services_selection = [
@@ -43,9 +43,9 @@
4343

4444

4545
@pytest.fixture(scope="module")
46-
async def services_metadata_in_db(
47-
asyncpg_engine: AsyncEngine,
48-
) -> AsyncIterator[list[dict]]:
46+
def services_metadata_in_db(
47+
postgres_db: sa.engine.Engine,
48+
) -> Iterator[list[dict]]:
4949
"""Pre-populate services metadata table with test data maintaining original structure."""
5050
services_data = [
5151
random_service_meta_data(
@@ -78,12 +78,12 @@ async def services_metadata_in_db(
7878
),
7979
]
8080

81-
async with AsyncExitStack() as stack:
81+
with ExitStack() as stack:
8282
created_services = []
8383
for service_data in services_data:
84-
row = await stack.enter_async_context(
85-
insert_and_get_row_lifespan(
86-
asyncpg_engine,
84+
row = stack.enter_context(
85+
sync_insert_and_get_row_lifespan(
86+
postgres_db,
8787
table=services_meta_data,
8888
values=service_data,
8989
pk_cols=[services_meta_data.c.key, services_meta_data.c.version],
@@ -95,9 +95,9 @@ async def services_metadata_in_db(
9595

9696

9797
@pytest.fixture(scope="module")
98-
async def services_consume_filetypes_in_db(
99-
asyncpg_engine: AsyncEngine, services_metadata_in_db: list[dict]
100-
) -> AsyncIterator[list[dict]]:
98+
def services_consume_filetypes_in_db(
99+
postgres_db: sa.engine.Engine, services_metadata_in_db: list[dict]
100+
) -> Iterator[list[dict]]:
101101
"""Pre-populate services consume filetypes table with test data."""
102102
filetypes_data = [
103103
random_service_consume_filetype(
@@ -183,12 +183,12 @@ async def services_consume_filetypes_in_db(
183183
),
184184
]
185185

186-
async with AsyncExitStack() as stack:
186+
with ExitStack() as stack:
187187
created_filetypes = []
188188
for filetype_data in filetypes_data:
189-
row = await stack.enter_async_context(
190-
insert_and_get_row_lifespan(
191-
asyncpg_engine,
189+
row = stack.enter_context(
190+
sync_insert_and_get_row_lifespan(
191+
postgres_db,
192192
table=services_consume_filetypes,
193193
values=filetype_data,
194194
pk_cols=[
@@ -204,9 +204,9 @@ async def services_consume_filetypes_in_db(
204204

205205

206206
@pytest.fixture(scope="module")
207-
async def services_access_rights_in_db(
208-
asyncpg_engine: AsyncEngine, services_metadata_in_db: list[dict]
209-
) -> AsyncIterator[list[dict]]:
207+
def services_access_rights_in_db(
208+
postgres_db: sa.engine.Engine, services_metadata_in_db: list[dict]
209+
) -> Iterator[list[dict]]:
210210
"""Pre-populate services access rights table with test data."""
211211
access_rights_data = [
212212
random_service_access_rights(
@@ -235,12 +235,12 @@ async def services_access_rights_in_db(
235235
),
236236
]
237237

238-
async with AsyncExitStack() as stack:
238+
with ExitStack() as stack:
239239
created_access_rights = []
240240
for access_data in access_rights_data:
241-
row = await stack.enter_async_context(
242-
insert_and_get_row_lifespan(
243-
asyncpg_engine,
241+
row = stack.enter_context(
242+
sync_insert_and_get_row_lifespan(
243+
postgres_db,
244244
table=services_access_rights,
245245
values=access_data,
246246
pk_cols=[

services/web/server/tests/unit/with_dbs/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,6 @@ async def aiopg_engine(postgres_db: sa.engine.Engine) -> AsyncIterator[aiopg.sa.
564564
await engine.wait_closed()
565565

566566

567-
@pytest.fixture(scope="module")
568567
async def asyncpg_engine( # <-- WE SHOULD USE THIS ONE instead of aiopg_engine
569568
postgres_db: sa.engine.Engine, is_pdb_enabled: bool
570569
) -> AsyncIterable[AsyncEngine]:

0 commit comments

Comments
 (0)