Files
2026-05-23 10:46:51 -04:00

39 lines
1.1 KiB
Python

"""
tests/conftest.py
-----------------
Shared pytest fixtures for LottoSight test suite.
Uses a temporary in-memory / temp-file SQLite DB so tests
never touch the real lottosight.db.
"""
import os
import sys
import tempfile
import pytest
# Ensure project root is on the path so db/core imports resolve
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@pytest.fixture(scope="function")
def tmp_db(monkeypatch, tmp_path):
"""
Redirect DB_PATH to a fresh temp file for each test function.
Initializes the schema and seeds default games.
Cleaned up automatically by pytest after each test.
"""
db_file = tmp_path / "test_lottosight.db"
# Patch the DB_PATH in database module before init
import db.database as database_module
monkeypatch.setattr(database_module, "DB_PATH", str(db_file))
# Also patch it in models (it imports get_connection which reads DB_PATH)
# get_connection() reads DB_PATH at call time, so patching database_module is enough
from db.database import init_db
init_db()
yield str(db_file)
# tmp_path is auto-cleaned by pytest