05/23 Phase 1
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
"""
|
||||
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
|
||||
Reference in New Issue
Block a user