faust icon indicating copy to clipboard operation
faust copied to clipboard

Pytest hangs with scope='session' async fixture

Open snb2013 opened this issue 1 year ago • 0 comments

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

snb2013 avatar Aug 15 '24 09:08 snb2013