Skip to content

Question: how to set fixture and async function same loop? #983

@Provinm

Description

@Provinm

here is my code

test_something.py

@pytest_asyncio.fixture(scope="session")
async def setup_env():
    import asyncio

    loop1 = asyncio.get_running_loop()
    print(f"setup_env {loop1} - {id(loop1)}")
    
    yield 




async def test_endpoints(setup_env: t.Generator) -> None:
    import asyncio

    loop2 = asyncio.get_running_loop()
    print(f"test_endpoints {loop2} - {id(loop2)}")

and conftest.py

def pytest_collection_modifyitems(items: t.List[Item]) -> None:
    pytest_asyncio_tests = (item for item in items if is_async_test(item))
    session_scope_marker = pytest.mark.asyncio(loop_scope="session")
    for async_test in pytest_asyncio_tests:
        async_test.add_marker(session_scope_marker, append=False)

my question is how to make loop1 == loop2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions