Spaces:
Sleeping
Sleeping
File size: 1,086 Bytes
52a4f3c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | """
Pytest configuration and fixtures for Chess Master tests.
Sets up shared test environment including database manager.
"""
import pytest
import tempfile
from pathlib import Path
import db.database as db_module
@pytest.fixture(scope="function", autouse=True)
def setup_test_db():
"""
Auto-use fixture to set up a temporary database for each test.
This ensures that the global database manager is initialized for tests
that rely on module-level functions like get_player().
"""
# Create temp database
with tempfile.TemporaryDirectory() as tmpdir:
db_path = Path(tmpdir) / "test_chess_club.db"
db_url = f"sqlite:///{db_path}"
# Create and initialize manager
manager = db_module.DatabaseManager(database_url=db_url)
manager.initialize()
# Store original manager
old_manager = db_module._db_manager
# Set global manager
db_module._db_manager = manager
yield manager
# Restore original manager
db_module._db_manager = old_manager
manager.close()
|