Production code shouldn't branch on `"pytest" in sys.modules` — it's fragile and couples db.py to test tooling. Instead, conftest.py now builds its own dedicated NullPool engine directly from settings, used only for the drop_all/create_all reset and the get_db override. The production engine in app/db.py is untouched and never exercised during tests, so this fully preserves the event-loop fix while keeping prod code test-agnostic.
17 lines
452 B
Python
17 lines
452 B
Python
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
|
from sqlalchemy.orm import DeclarativeBase
|
|
|
|
from app.config import settings
|
|
|
|
engine = create_async_engine(settings.database_url, echo=False)
|
|
async_session_maker = async_sessionmaker(engine, expire_on_commit=False)
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
|
|
async def get_db() -> AsyncSession:
|
|
async with async_session_maker() as session:
|
|
yield session
|