34 lines
1 KiB
Python
34 lines
1 KiB
Python
import os
|
|
import pytest
|
|
import pytest_asyncio
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
# Supply minimal dummy env-vars *before* any of our modules are imported. #
|
|
# This lets the global `settings = Settings()` call succeed. #
|
|
# --------------------------------------------------------------------------- #
|
|
os.environ.update(
|
|
{
|
|
"DB_URI": "sqlite+aiosqlite:///:memory:",
|
|
"ECHO_SQL": "false",
|
|
"SECRET_KEY": "test-secret",
|
|
"REFRESH_SECRET_KEY": "test-refresh",
|
|
"API_KEY": "test-key",
|
|
}
|
|
)
|
|
|
|
from fooder.db import DatabaseSessionManager
|
|
from fooder.domain import Base
|
|
from fooder.settings import settings
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def db_manager() -> DatabaseSessionManager:
|
|
return DatabaseSessionManager(settings)
|
|
|
|
|
|
@pytest_asyncio.fixture(scope="session", autouse=True)
|
|
async def setup_database(db_manager: DatabaseSessionManager):
|
|
async with db_manager.connect() as conn:
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
|
|
yield
|