Skip to content

Commit b1497aa

Browse files
EstrellaXDclaude
andcommitted
fix(test): invalidate module-level bangumi cache between tests
The BangumiDatabase.search_all() uses a module-level TTL cache that persists across tests using different in-memory SQLite databases. This caused test_migrate_preserves_existing_data and test_migrate_idempotent to return stale cached results (1 bangumi instead of 2). Add an autouse fixture in conftest.py to clear the cache before and after each test. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent eefe85d commit b1497aa

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

backend/src/test/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from sqlmodel import Session, SQLModel, create_engine
99

1010
from module.api import v1
11+
from module.database.bangumi import _invalidate_bangumi_cache
1112
from module.models.config import Config
1213
from module.models import ResponseModel
1314
from module.security.api import get_current_user
@@ -18,6 +19,19 @@
1819
# ---------------------------------------------------------------------------
1920

2021

22+
@pytest.fixture(autouse=True)
23+
def _clear_bangumi_cache():
24+
"""Invalidate the module-level bangumi cache before each test.
25+
26+
The BangumiDatabase.search_all() uses a module-level TTL cache that
27+
persists across tests using different in-memory databases, causing
28+
stale results.
29+
"""
30+
_invalidate_bangumi_cache()
31+
yield
32+
_invalidate_bangumi_cache()
33+
34+
2135
@pytest.fixture
2236
def db_engine():
2337
"""Create an in-memory SQLite engine for testing."""

0 commit comments

Comments
 (0)