generated from john/python-template
V4.2 complete
This commit is contained in:
+12
-3
@@ -4,6 +4,8 @@ Every test gets a fresh in-memory SQLite database so tests are
|
||||
isolated, fast, and leave no artifacts on disk.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
from sqlmodel import Session
|
||||
@@ -12,7 +14,7 @@ from sqlmodel import create_engine
|
||||
from sqlmodel.pool import StaticPool
|
||||
|
||||
from transcription.config import Settings
|
||||
from transcription.config import get_settings
|
||||
from transcription.config import SqliteSettings
|
||||
from transcription.db.engine import get_database_url
|
||||
from transcription.db.engine import get_engine
|
||||
from transcription.db.session import dispose_session_factory
|
||||
@@ -37,10 +39,17 @@ def session():
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def default_settings():
|
||||
async def default_settings(tmp_path):
|
||||
"""Provide default settings for tests."""
|
||||
settings = get_settings(database_url="sqlite:///:memory:")
|
||||
database_path = tmp_path / "tests.db"
|
||||
settings = Settings(
|
||||
openrouter_api_key="test-key",
|
||||
database=SqliteSettings(path=str(database_path)),
|
||||
environment="test",
|
||||
)
|
||||
db_url = get_database_url(settings)
|
||||
if Path(str(get_engine(database_url=db_url).url.database)).resolve() != database_path.resolve():
|
||||
raise RuntimeError(f"Refusing to initialize destructive test fixtures against {db_url}")
|
||||
await dispose_session_factory(db_url)
|
||||
engine = get_engine(database_url=db_url)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user