From daa7a206791edf7655d44032aeeb3de1aa79b388 Mon Sep 17 00:00:00 2001 From: Zihao Xu Date: Mon, 19 Jan 2026 04:46:59 -0800 Subject: [PATCH] test: add fixed_random_seed fixture with autouse=True (#52) Ensures all tests have deterministic random behavior by setting random.seed(42) before each test. This prevents flaky tests caused by random number generation. Closes #44 --- tests/conftest.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index b19beaa..f700c47 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,7 +1,18 @@ import pytest +import random from unittest.mock import MagicMock, AsyncMock, patch from src.classes.map import Map + + +@pytest.fixture(autouse=True) +def fixed_random_seed(): + """ + Ensure all tests have deterministic random behavior. + This fixture is automatically applied to all tests. + """ + random.seed(42) + yield from src.classes.tile import TileType, Tile from src.classes.world import World from src.classes.calendar import Month, Year, create_month_stamp