"""Test fixtures for the Temporal demo.""" from contextlib import AsyncExitStack import pytest_asyncio from httpx import ASGITransport, AsyncClient from temporalio.testing import WorkflowEnvironment from app.config.settings import get_settings from app.infra.db.session import dispose_database, init_database from app.infra.temporal.client import set_temporal_client from app.main import create_app from app.workers.runner import build_workers @pytest_asyncio.fixture async def api_runtime(tmp_path, monkeypatch): """Provide an API client and in-memory Temporal test environment.""" db_path = tmp_path / "test.db" monkeypatch.setenv("DATABASE_URL", f"sqlite+aiosqlite:///{db_path.as_posix()}") monkeypatch.setenv("AUTO_CREATE_TABLES", "true") get_settings.cache_clear() await dispose_database() await init_database() app = create_app() async with await WorkflowEnvironment.start_time_skipping() as env: set_temporal_client(env.client) async with AsyncExitStack() as stack: for worker in build_workers(env.client): await stack.enter_async_context(worker) async with AsyncClient( transport=ASGITransport(app=app), base_url="http://testserver", ) as client: yield client, env set_temporal_client(None) await dispose_database() get_settings.cache_clear()