generated from john/python-template
started test_job_service
This commit is contained in:
+19
-4
@@ -5,18 +5,33 @@ isolated, fast, and leave no artifacts on disk.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from sqlmodel import Session, SQLModel, create_engine
|
||||
import pytest_asyncio
|
||||
from sqlmodel import Session
|
||||
from sqlmodel import SQLModel
|
||||
from sqlmodel import create_engine
|
||||
from sqlmodel.pool import StaticPool
|
||||
|
||||
from transcription.db.runtime import dispose_database_runtime
|
||||
from transcription.db.runtime import get_session
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def session():
|
||||
"""Provide a clean database session for each test."""
|
||||
"""Provide a clean synchronous database session for sync tests."""
|
||||
engine = create_engine(
|
||||
"sqlite://",
|
||||
connect_args={"check_same_thread": False},
|
||||
poolclass=StaticPool,
|
||||
)
|
||||
SQLModel.metadata.create_all(engine)
|
||||
with Session(engine) as session:
|
||||
yield session
|
||||
with Session(engine) as sync_session:
|
||||
yield sync_session
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def async_session():
|
||||
"""Provide a clean asynchronous database session for async tests."""
|
||||
async with get_session() as async_session:
|
||||
yield async_session
|
||||
|
||||
await dispose_database_runtime()
|
||||
|
||||
Reference in New Issue
Block a user