Skip to content

Commit 4ecc210

Browse files
committed
new module
1 parent dad8e86 commit 4ecc210

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import asyncio
2+
3+
import pytest
4+
import uvloop
5+
6+
pytest_plugins = [
7+
"aiohttp.pytest_plugin", # No need to install pytest-aiohttp separately
8+
]
9+
10+
11+
@pytest.fixture(scope="session")
12+
def event_loop_policy():
13+
"""Override the event loop policy to use uvloop which is the one we use in production
14+
15+
SEE https://pytest-asyncio.readthedocs.io/en/stable/how-to-guides/uvloop.html
16+
"""
17+
return uvloop.EventLoopPolicy()
18+
19+
20+
@pytest.fixture
21+
async def loop() -> asyncio.AbstractEventLoop:
22+
"""Override the event loop inside aiohttp.pytest_plugin with the one from pytest-asyncio.
23+
24+
25+
Otherwise error like this will be raised:
26+
27+
> if connector._loop is not loop:
28+
> raise RuntimeError("Session and connector has to use same event loop")
29+
E RuntimeError: Session and connector has to use same event loop
30+
31+
.venv/lib/python3.11/site-packages/aiohttp/client.py:375: RuntimeError
32+
33+
> if connector._loop is not loop:
34+
> raise RuntimeError("Session and connector has to use same event loop")
35+
>E RuntimeError: Session and connector has to use same event loop
36+
37+
.venv/lib/python3.11/site-packages/aiohttp/client.py:375: RuntimeError
38+
"""
39+
return asyncio.get_running_loop()

services/web/server/tests/conftest.py

Lines changed: 1 addition & 7 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
@@ -66,6 +65,7 @@
6665
# imports the fixtures for the integration tests
6766
pytest_plugins = [
6867
"aiohttp.pytest_plugin",
68+
"pytest_simcore.asyncio_event_loops",
6969
"pytest_simcore.cli_runner",
7070
"pytest_simcore.db_entries_mocks",
7171
"pytest_simcore.docker_compose",
@@ -488,9 +488,3 @@ def mock_dynamic_scheduler(mocker: MockerFixture) -> None:
488488
"simcore_service_webserver.dynamic_scheduler.api.update_projects_networks",
489489
autospec=True,
490490
)
491-
492-
493-
@pytest.fixture
494-
async def loop() -> asyncio.AbstractEventLoop:
495-
"""Override the event loop inside pytest-aiohttp with the one from pytest-asyncio."""
496-
return asyncio.get_running_loop()

0 commit comments

Comments
 (0)