File tree Expand file tree Collapse file tree 2 files changed +40
-7
lines changed
packages/pytest-simcore/src/pytest_simcore
services/web/server/tests Expand file tree Collapse file tree 2 files changed +40
-7
lines changed Original file line number Diff line number Diff line change 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 ()
Original file line number Diff line number Diff line change 33# pylint: disable=unused-argument
44# pylint: disable=unused-variable
55
6- import asyncio
76import contextlib
87import json
98import logging
6665# imports the fixtures for the integration tests
6766pytest_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 ()
You can’t perform that action at this time.
0 commit comments