Skip to content

Unexpected behavior when defining custom loop policy #591

Closed
@schlamar

Description

@schlamar

When defining a custom loop policy in a fixture, the first test is executed with the loop from the default event loop policy and not from the custom loop policy. I assume pytest-asyncio creates the first event loop before the fixture for the custom loop policy has run.

Simple reproduction test (Windows):

import asyncio
import pytest


@pytest.fixture(autouse=True, scope="module")
def set_loop_policy():
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())


@pytest.mark.asyncio
async def test_loop(event_loop):
    assert isinstance(event_loop, asyncio.SelectorEventLoop)


@pytest.mark.asyncio
async def test_loop_second(event_loop):
    assert isinstance(event_loop, asyncio.SelectorEventLoop)

The first test fails, the second passes. I would expect that both tests pass.

Related to #587 and #588

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions