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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user