Files
audio-engine-hub/tests/conftest.py
2025-12-04 11:58:36 +01:00

34 lines
1.1 KiB
Python

import pytest
from fastapi.testclient import TestClient
from main import create_app # Import the app factory function
from config import settings # Import settings to monkeypatch
import os
@pytest.fixture
def tmp_audio_dir(tmp_path):
"""Provides a temporary directory for audio caching for each test."""
audio_dir = tmp_path / "test_audio_cache"
audio_dir.mkdir()
return audio_dir
@pytest.fixture
def app_instance(tmp_audio_dir, monkeypatch):
"""
Provides a fresh FastAPI application instance for each test,
with its AUDIO_CACHE_DIR redirected to a temporary location.
"""
monkeypatch.setattr(settings, "AUDIO_CACHE_DIR", str(tmp_audio_dir))
app = create_app()
return app
@pytest.fixture
def app_client(app_instance):
"""Provides a TestClient instance for the FastAPI application."""
with TestClient(app_instance) as client:
yield client
@pytest.fixture
def piper_engine(app_instance):
"""Provides the PiperEngine instance from the registry of the fresh app instance."""
# Access the engine registry from the app_instance
return app_instance.ENGINE_REGISTRY.get("piper")