Skip to content

Commit 5141965

Browse files
committed
Configure the async loop at test session start
Doing it in a fixture is too late: event_loop might have already been called if the first test running is async, and it would fail on Windows. This started to be needed after pytest-asyncio 0.17.0 was released. See <pytest-dev/pytest-asyncio#256>.
1 parent da482bf commit 5141965

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

tests/conftest.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,15 @@ def retries(request):
6262
)
6363

6464

65-
@pytest.fixture
66-
def event_loop(request):
67-
"""Return the event loop to test asyncio-marked tests."""
68-
# pytest-asyncio reset the the loop config after each test, so set
69-
# set them each time
70-
71-
loop = request.config.getoption("--loop")
65+
def pytest_sessionstart(session):
66+
# Configure the async loop.
67+
loop = session.config.getoption("--loop")
7268
if loop == "uvloop":
7369
import uvloop
7470

7571
uvloop.install()
7672
else:
7773
assert loop == "default"
7874

79-
loop = None
8075
if sys.platform == "win32":
8176
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
82-
if not loop:
83-
loop = asyncio.get_event_loop_policy().new_event_loop()
84-
yield loop
85-
loop.close()

0 commit comments

Comments
 (0)