"""pytest fixtures for NSCT tests.""" from __future__ import annotations import os from typing import AsyncGenerator import pytest import pytest_asyncio from fastapi.testclient import TestClient from httpx import AsyncClient from nsct.api.main import create_app from nsct.config import AppSettings @pytest.fixture(scope="session") def app() -> AppSettings: """Minimal AppSettings for test environment.""" return AppSettings.from_env() @pytest.fixture(scope="session") def client(app: AppSettings): """Synchronous test client for the FastAPI app.""" fastapi_app = create_app() with TestClient(fastapi_app) as c: yield c @pytest_asyncio.fixture(scope="function") async def async_client(app: AppSettings) -> AsyncGenerator[AsyncClient, None]: """Async test client for the FastAPI app.""" fastapi_app = create_app() async with AsyncClient(app=fastapi_app, base_url="http://test") as ac: yield ac @pytest.fixture(scope="function") def clean_env(monkeypatch: pytest.MonkeyPatch) -> None: """Ensure environment has the minimum required vars for AppSettings.""" monkeypatch.setenv("NSCT_LLM_BASE_URL", "http://localhost:8030/openai/v1") monkeypatch.setenv("NSCT_LLM_MODEL", "test-model") monkeypatch.setenv("NSCT_LLM_MAX_CONCURRENCY", "1") monkeypatch.setenv("NSCT_VISION_BASE_URL", "http://localhost:8030/openai/visual/v1") monkeypatch.setenv("NSCT_VISION_MODEL", "test-model") monkeypatch.setenv("NSCT_AUDIO_BASE_URL", "http://localhost:8030/hermes-audio") monkeypatch.setenv("NSCT_AUDIO_MODEL", "default") monkeypatch.setenv("NSCT_DB_URL", "sqlite+aiosqlite:///:memory:") monkeypatch.setenv("NSCT_DEBUG", "false")