Initial extraction from monorepo
This commit is contained in:
commit
f7ef7ca4ab
56 changed files with 6163 additions and 0 deletions
36
tests/conftest.py
Normal file
36
tests/conftest.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
"""Shared pytest fixtures.
|
||||
|
||||
Tests run against an in-memory SQLite DB created via the SQLAlchemy ORM
|
||||
metadata directly — fast, deterministic, and avoids running Alembic
|
||||
end-to-end on every test (the migration is exercised separately).
|
||||
"""
|
||||
from collections.abc import AsyncIterator
|
||||
|
||||
import pytest_asyncio
|
||||
from sqlalchemy.ext.asyncio import (
|
||||
AsyncEngine,
|
||||
AsyncSession,
|
||||
async_sessionmaker,
|
||||
create_async_engine,
|
||||
)
|
||||
|
||||
from fire_planner.db import SCHEMA_NAME, Base
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def engine() -> AsyncIterator[AsyncEngine]:
|
||||
eng = create_async_engine("sqlite+aiosqlite:///:memory:")
|
||||
async with eng.begin() as conn:
|
||||
# SQLite has no schema concept — attach an in-memory DB under the
|
||||
# `fire_planner` name so `__table_args__ = {"schema": ...}` resolves.
|
||||
await conn.exec_driver_sql(f"ATTACH DATABASE ':memory:' AS {SCHEMA_NAME}")
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
yield eng
|
||||
await eng.dispose()
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def session(engine: AsyncEngine) -> AsyncIterator[AsyncSession]:
|
||||
factory = async_sessionmaker(engine, expire_on_commit=False)
|
||||
async with factory() as sess:
|
||||
yield sess
|
||||
Loading…
Add table
Add a link
Reference in a new issue