79584056

Date: 2025-04-21 05:11:19
Score: 1
Natty:
Report link

Thanks to Boris's advice, I managed to find a bug in the tests. An async fixture with session visibility was declared. Which created another event_loop and led to the problem.

Here is the code with the error:

@pytest_asyncio.fixture(scope="session")
async def engine(app_database_url, migrations) -> AsyncEngine:
"""Creates a SQLAlchemy engine to interact with the database."""

engine = create_async_engine(app_database_url)
yield engine
await engine.dispose()

To fix it, just need to remove scope="session" from the decorator.

And then it will become a foonction scope like all other fixtures and will not create its own separate event_loop

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: DenisMaslennikov