fix: lock_tables acquires dedicated session to enforce RAII lock boundaries (#261)

This commit is contained in:
d3vyce
2026-04-26 11:53:29 +02:00
committed by GitHub
parent 0945fadfb8
commit 626b97cadd
4 changed files with 110 additions and 88 deletions
+15
View File
@@ -439,6 +439,21 @@ async def engine():
await engine.dispose()
@pytest.fixture(scope="function")
async def session_maker(engine):
"""Provide a session factory with tables created and dropped around the test."""
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
factory = async_sessionmaker(engine, expire_on_commit=False)
try:
yield factory
finally:
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.drop_all)
@pytest.fixture(scope="function")
async def db_session(engine):
"""Create a test database session with tables.