- Create tests/conftest.py with testcontainers for Postgres and Redis - Auto-detect Docker Desktop socket and disable Ryuk for compatibility - Update tests/db/conftest.py and tests/services/conftest.py to use shared fixtures - Fix test_resolve_effect_logs_exceptions: logger was disabled by pytest - Fix test_save_and_load_with_real_redis: use redis_url fixture - Minor lint fix in engine_validation.py Tests now auto-start containers on run - no need for `docker compose up` All 1199 tests passing. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
"""Service-specific test fixtures for Mantimon TCG.
|
|
|
|
This module extends the shared fixtures from tests/conftest.py with
|
|
service-test-specific helpers like GameState factories.
|
|
|
|
The db_session and redis_client fixtures are inherited from the parent conftest.
|
|
"""
|
|
|
|
from uuid import uuid4
|
|
|
|
import pytest
|
|
|
|
from app.core.config import RulesConfig
|
|
from app.core.enums import TurnPhase
|
|
from app.core.models.game_state import GameState, PlayerState
|
|
|
|
# =============================================================================
|
|
# GameState Factory
|
|
# =============================================================================
|
|
|
|
|
|
def create_test_game_state(
|
|
game_id: str | None = None,
|
|
turn_number: int = 1,
|
|
phase: TurnPhase = TurnPhase.MAIN,
|
|
) -> GameState:
|
|
"""Create a minimal GameState for testing.
|
|
|
|
Args:
|
|
game_id: Optional game ID. Generated if not provided.
|
|
turn_number: Turn number (default 1).
|
|
phase: Turn phase (default MAIN).
|
|
|
|
Returns:
|
|
A minimal valid GameState for testing.
|
|
"""
|
|
if game_id is None:
|
|
game_id = str(uuid4())
|
|
|
|
return GameState(
|
|
game_id=game_id,
|
|
rules=RulesConfig(),
|
|
card_registry={},
|
|
players={
|
|
"player1": PlayerState(player_id="player1"),
|
|
"player2": PlayerState(player_id="player2"),
|
|
},
|
|
current_player_id="player1",
|
|
turn_number=turn_number,
|
|
phase=phase,
|
|
turn_order=["player1", "player2"],
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def game_state() -> GameState:
|
|
"""Provide a test GameState."""
|
|
return create_test_game_state()
|