Do testing on isolated DB

This commit is contained in:
Jack Kingsman
2026-02-11 11:23:38 -08:00
parent f52feb2d5c
commit 29f0518698
+19
View File
@@ -1,7 +1,26 @@
"""Pytest configuration and shared fixtures."""
import os
import shutil
import tempfile
from pathlib import Path
import pytest
# Use an isolated file-backed SQLite DB for tests that import app.main/TestClient.
# This must be set before app.config/app.database are imported, otherwise the global
# Database instance will bind to the default runtime DB (data/meshcore.db).
_TEST_DB_DIR = Path(tempfile.mkdtemp(prefix="meshcore-pytest-"))
_TEST_DB_PATH = _TEST_DB_DIR / "meshcore.db"
os.environ.setdefault("MESHCORE_DATABASE_PATH", str(_TEST_DB_PATH))
@pytest.fixture(scope="session", autouse=True)
def cleanup_test_db_dir():
"""Clean up temporary pytest DB directory after the test session."""
yield
shutil.rmtree(_TEST_DB_DIR, ignore_errors=True)
@pytest.fixture
def sample_channel_key():