Skip to content

event_loop_policy for single test #1101

Open
@Dreamsorcerer

Description

@Dreamsorcerer

It would be good if there was an easy way to change the event_loop_policy for a single test. I can't see any way to do this currently from the documentation (other than moving a single test to it's own module).

In aiohttp, we currently have these fixtures in conftest.py, which I'm looking to remove:

@pytest.fixture
def selector_loop() -> Iterator[asyncio.AbstractEventLoop]:
    policy = asyncio.WindowsSelectorEventLoopPolicy()  # type: ignore[attr-defined]
    asyncio.set_event_loop_policy(policy)

    with loop_context(policy.new_event_loop) as:
        asyncio.set_event_loop(_loop)
        yield _loop


@pytest.fixture
def uvloop_loop() -> Iterator[asyncio.AbstractEventLoop]:
    policy = uvloop.EventLoopPolicy()
    asyncio.set_event_loop_policy(policy)

    with loop_context(policy.new_event_loop) as:
        asyncio.set_event_loop(_loop)
        yield _loop

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions