Skip to content

Commit 6ce16b8

Browse files
committed
1 parent c3fd298 commit 6ce16b8

File tree

7 files changed

+18
-27
lines changed

7 files changed

+18
-27
lines changed

packages/service-library/tests/aiohttp/test_client_session.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from collections.abc import Callable, Iterator
77
from typing import Any
88

9-
import pytest
9+
import pytest_asyncio
1010
from aiohttp import web
1111
from aiohttp.client import ClientSession
1212
from aiohttp.test_utils import TestServer
@@ -18,8 +18,8 @@
1818
)
1919

2020

21-
@pytest.fixture
22-
def server(event_loop, aiohttp_server: Callable) -> Iterator[TestServer]:
21+
@pytest_asyncio.fixture(loop_scope="function", scope="function")
22+
async def server(aiohttp_server: Callable) -> Iterator[TestServer]:
2323
async def echo(request):
2424
got = await request.json()
2525
return web.json_response(data=got)
@@ -31,7 +31,7 @@ async def echo(request):
3131

3232
assert not app.get(APP_CLIENT_SESSION_KEY)
3333

34-
test_server = event_loop.run_until_complete(aiohttp_server(app))
34+
test_server = await aiohttp_server(app)
3535

3636
assert isinstance(app[APP_CLIENT_SESSION_KEY], ClientSession)
3737
assert not app[APP_CLIENT_SESSION_KEY].closed

packages/service-library/tests/aiohttp/test_monitor_slow_callbacks.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from collections.abc import Iterable
99

1010
import pytest
11+
import pytest_asyncio
1112
from servicelib.aiohttp import monitor_slow_callbacks
1213
from servicelib.aiohttp.aiopg_utils import DatabaseError
1314
from tenacity import retry
@@ -24,11 +25,12 @@ async def fails_to_reach_pg_db():
2425
raise DatabaseError
2526

2627

27-
@pytest.fixture
28-
def incidents_manager(event_loop) -> dict:
28+
@pytest_asyncio.fixture(loop_scope="function", scope="function")
29+
async def incidents_manager() -> dict:
2930
incidents = []
3031
monitor_slow_callbacks.enable(slow_duration_secs=0.2, incidents=incidents)
3132

33+
event_loop = asyncio.get_running_loop()
3234
asyncio.ensure_future(slow_task(0.3), loop=event_loop) # noqa: RUF006
3335
asyncio.ensure_future(slow_task(0.3), loop=event_loop) # noqa: RUF006
3436
asyncio.ensure_future(slow_task(0.4), loop=event_loop) # noqa: RUF006

packages/service-library/tests/aiohttp/test_requests_validation.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from uuid import UUID
88

99
import pytest
10+
import pytest_asyncio
1011
from aiohttp import web
1112
from aiohttp.test_utils import TestClient, make_mocked_request
1213
from common_library.json_serialization import json_dumps
@@ -98,8 +99,8 @@ def create_fake(cls, faker: Faker):
9899
return cls(x=faker.pyint(), y=faker.pybool(), z=Sub.create_fake(faker))
99100

100101

101-
@pytest.fixture
102-
def client(event_loop, aiohttp_client: Callable, faker: Faker) -> TestClient:
102+
@pytest_asyncio.fixture(loop_scope="function", scope="function")
103+
async def client(aiohttp_client: Callable, faker: Faker) -> TestClient:
103104
"""
104105
Some app that:
105106
@@ -162,7 +163,7 @@ async def _middleware(request: web.Request, handler):
162163
# adds handler
163164
app.add_routes([web.get("/projects/{project_uuid}", _handler)])
164165

165-
return event_loop.run_until_complete(aiohttp_client(app))
166+
return await aiohttp_client(app)
166167

167168

168169
@pytest.fixture

services/web/server/tests/conftest.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# pylint: disable=unused-argument
44
# pylint: disable=unused-variable
55

6-
import asyncio
76
import contextlib
87
import json
98
import logging
@@ -488,11 +487,3 @@ def mock_dynamic_scheduler(mocker: MockerFixture) -> None:
488487
"simcore_service_webserver.dynamic_scheduler.api.update_projects_networks",
489488
autospec=True,
490489
)
491-
492-
493-
@pytest.fixture
494-
async def loop(
495-
event_loop: asyncio.AbstractEventLoop,
496-
) -> asyncio.AbstractEventLoop:
497-
"""Override the event loop inside pytest-aiohttp with the one from pytest-asyncio."""
498-
return event_loop

services/web/server/tests/unit/with_dbs/03/test_login_auth_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async def auth_app(
3737
return app
3838

3939

40-
@pytest_asyncio.fixture(loop_scope="function")
40+
@pytest_asyncio.fixture(loop_scope="function", scope="function")
4141
async def web_server(
4242
postgres_db: sa.engine.Engine,
4343
auth_app: web.Application,

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# pylint: disable=unused-variable
44
# pylint: disable=too-many-arguments
55

6-
import asyncio
76
from collections.abc import AsyncGenerator, AsyncIterable, Callable
87
from typing import Any
98

109
import pytest
10+
import pytest_asyncio
1111
import sqlalchemy as sa
1212
from aiohttp import web
1313
from aiohttp.test_utils import TestServer
@@ -22,9 +22,8 @@
2222
from sqlalchemy.ext.asyncio import AsyncEngine
2323

2424

25-
@pytest.fixture
26-
def web_server(
27-
event_loop: asyncio.AbstractEventLoop,
25+
@pytest_asyncio.fixture(loop_scope="function", scope="function")
26+
async def web_server(
2827
app_environment: EnvVarsDict, # configs
2928
postgres_db: sa.engine.Engine, # db-ready
3029
webserver_test_server_port: int,
@@ -37,9 +36,7 @@ def web_server(
3736
setup_settings(app)
3837
setup_db(app)
3938

40-
return event_loop.run_until_complete(
41-
aiohttp_server(app, port=webserver_test_server_port)
42-
)
39+
return await aiohttp_server(app, port=webserver_test_server_port)
4340

4441

4542
@pytest.fixture

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ async def _print_mail_to_stdout(
205205
)
206206

207207

208-
@pytest_asyncio.fixture(loop_scope="function")
208+
@pytest_asyncio.fixture(loop_scope="function", scope="function")
209209
async def web_server(
210210
app_environment: EnvVarsDict,
211211
postgres_db: sa.engine.Engine,

0 commit comments

Comments
 (0)