vigilar/tests/conftest.py
Aaron D. Lee 2b3a4ba853 Add pet and wildlife counts to daily digest
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-03 13:24:33 -04:00

45 lines
1.1 KiB
Python

"""Pytest fixtures for Vigilar tests."""
import os
import tempfile
from pathlib import Path
import pytest
from sqlalchemy import create_engine, event
from vigilar.config import VigilarConfig, load_config
from vigilar.storage.schema import metadata
def _create_test_engine(db_path: Path):
"""Create a fresh engine for testing (bypasses the global singleton)."""
db_path.parent.mkdir(parents=True, exist_ok=True)
engine = create_engine(f"sqlite:///{db_path}", echo=False)
metadata.create_all(engine)
return engine
@pytest.fixture
def tmp_data_dir(tmp_path):
"""Temporary data directory for tests."""
data_dir = tmp_path / "data"
data_dir.mkdir(exist_ok=True)
return data_dir
@pytest.fixture
def test_db(tmp_path):
"""Create an isolated test database (no shared state between tests)."""
db_path = tmp_path / "data" / "test.db"
return _create_test_engine(db_path)
@pytest.fixture
def sample_config():
"""Return a minimal VigilarConfig for testing."""
return VigilarConfig(
cameras=[],
sensors=[],
rules=[],
)