fix: isolate tests from production database

Tests that imported wled_controller.main at module level caused the real
production database (data/ledgrab.db) to be opened before test fixtures
could patch the config. This led to silent data loss.

Patch the global config singleton at conftest module level (before any
test imports main.py) to redirect all DB access to a temp directory.
This commit is contained in:
2026-04-01 19:01:56 +03:00
parent 6b0e4e5539
commit 992495e2e4
3 changed files with 79 additions and 24 deletions
@@ -1,9 +1,7 @@
"""API tests for audio processing template endpoints."""
import pytest
from fastapi.testclient import TestClient
from wled_controller.main import app
from wled_controller.config import get_config
# Ensure audio filters registered
@@ -17,6 +15,9 @@ AUTH = {"Authorization": f"Bearer {_api_key}"} if _api_key else {}
@pytest.fixture(scope="module")
def client():
"""Provide a TestClient with lifespan (startup/shutdown) properly triggered."""
from fastapi.testclient import TestClient
from wled_controller.main import app
with TestClient(app) as c:
yield c