Skip to content

Pytest hangs with scope='session' async fixture #642

@snb2013

Description

@snb2013

Checklist

  • [v] I have included information about relevant versions
  • [v] I have verified that the issue persists when using the master branch of Faust.

Steps to reproduce

When using async fixtures with scope='session', test hangs.
Minimal example.

from asyncio import get_event_loop, sleep
import pytest

import faust

app = faust.App('example')

@app.agent()
async def bar(stream):
    async for value in stream:
        yield value

@pytest.fixture(scope='session')
def event_loop():
    loop = get_event_loop()
    yield loop

@pytest.fixture(scope='session')
async def session_ficture():
    await sleep(0)
    yield 1

@pytest.fixture(scope='function')
async def function_ficture():
    await sleep(0)
    yield 2

async def test_good(function_ficture):
    async with bar.test_context() as agent:
        await agent.put('hey')

async def test_hangs(session_ficture):
    async with bar.test_context() as agent:
        await agent.put('hey')

pytest.ini content:
[pytest]
asyncio_mode=auto

Expected behavior

Tests should not be hanged.

Actual behavior

Test 'test_hangs' is hanged.

Versions

  • Python version 3.12
  • Faust version 0.11.2
  • Operating system Ubuntu 23.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions