1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
"""
We support module-scoped async fixtures, but only if the event loop is
module-scoped too.
"""
from __future__ import annotations
import asyncio
import pytest
@pytest.fixture(scope="module")
def event_loop():
"""A module-scoped event loop."""
loop = asyncio.new_event_loop()
yield loop
loop.close()
@pytest.fixture(scope="module")
async def async_fixture():
await asyncio.sleep(0.1)
return 1
@pytest.mark.asyncio
async def test_async_fixture_scope(async_fixture):
assert async_fixture == 1
await asyncio.sleep(0.1)
|