Skip to content

_FakeScorer and _make_state duplicated in 3 test files — create conftest.py #59

@FlorentPoinsaut

Description

@FlorentPoinsaut

Description

_FakeScorer and _make_state are copy-pasted across three test files with no shared fixture:

  • tests/test_commands.py
  • tests/test_game_state.py
  • tests/test_overlay.py

This violates DRY and means any change to GameState's constructor signature requires updates in three places.

Fix

Create tests/conftest.py with shared pytest fixtures:

# tests/conftest.py
import pytest
from game.state import GameState

class _FakeScorer:
    def score_guess(self, guess: str, target: str) -> float | None:
        if not target:
            return None
        return min(1.0, len(guess) / len(target))

@pytest.fixture()
def fake_scorer() -> _FakeScorer:
    return _FakeScorer()

@pytest.fixture()
def game_state() -> GameState:
    return GameState()

@pytest.fixture()
def game_state_with_scorer() -> GameState:
    return GameState(scorer=_FakeScorer())

Then remove the duplicate definitions from the three test files and inject the fixtures via function parameters.

Identified by

🧪 [Tech] Tester

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low priority — nice to havecode qualityCode style, conventions, dead codetestingTest coverage and quality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions