1+ """
2+ Our choice of plugin to test asyncio functionality is pytest-asyncio
3+
4+ Some other pytest plugins, e.g. pytest-aiohttp, define their own event loop
5+ policies and event loops, which can conflict with pytest-asyncio.
6+
7+ This files unifies the event loop policy and event loop used by pytest-asyncio throughout
8+ all the tests in this repository.
9+
10+ """
11+
112import asyncio
213
314import pytest
415import uvloop
516
6- pytest_plugins = [
7- "aiohttp.pytest_plugin" , # No need to install pytest-aiohttp separately
8- ]
9-
1017
1118@pytest .fixture (scope = "session" )
1219def event_loop_policy ():
@@ -19,21 +26,30 @@ def event_loop_policy():
1926
2027@pytest .fixture
2128async def loop () -> asyncio .AbstractEventLoop :
22- """Override the event loop inside aiohttp.pytest_plugin with the one from pytest-asyncio.
29+ """Override the event loop inside `aiohttp.pytest_plugin` with the one from `pytest-asyncio`.
30+
31+ This provides the necessary fixtures to use pytest-asyncio with aiohttp!!!
32+
33+ USAGE:
34+
35+ pytest_plugins = [
36+ "aiohttp.pytest_plugin", # No need to install pytest-aiohttp separately
37+ ]
2338
2439
40+ ERRORS:
2541 Otherwise error like this will be raised:
2642
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
43+ > if connector._loop is not loop:
44+ > raise RuntimeError("Session and connector has to use same event loop")
45+ E RuntimeError: Session and connector has to use same event loop
3046
31- .venv/lib/python3.11/site-packages/aiohttp/client.py:375: RuntimeError
47+ .venv/lib/python3.11/site-packages/aiohttp/client.py:375: RuntimeError
3248
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
49+ > if connector._loop is not loop:
50+ > raise RuntimeError("Session and connector has to use same event loop")
51+ >E RuntimeError: Session and connector has to use same event loop
3652
37- .venv/lib/python3.11/site-packages/aiohttp/client.py:375: RuntimeError
53+ .venv/lib/python3.11/site-packages/aiohttp/client.py:375: RuntimeError
3854 """
3955 return asyncio .get_running_loop ()
0 commit comments