mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-03-20 03:46:40 +08:00
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>
This commit is contained in:
@@ -8,6 +8,7 @@ from fastapi.testclient import TestClient
|
||||
from sqlmodel import Session, SQLModel, create_engine
|
||||
|
||||
from module.api import v1
|
||||
from module.database.bangumi import _invalidate_bangumi_cache
|
||||
from module.models.config import Config
|
||||
from module.models import ResponseModel
|
||||
from module.security.api import get_current_user
|
||||
@@ -18,6 +19,19 @@ from module.security.api import get_current_user
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _clear_bangumi_cache():
|
||||
"""Invalidate the module-level bangumi cache before each test.
|
||||
|
||||
The BangumiDatabase.search_all() uses a module-level TTL cache that
|
||||
persists across tests using different in-memory databases, causing
|
||||
stale results.
|
||||
"""
|
||||
_invalidate_bangumi_cache()
|
||||
yield
|
||||
_invalidate_bangumi_cache()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def db_engine():
|
||||
"""Create an in-memory SQLite engine for testing."""
|
||||
|
||||
Reference in New Issue
Block a user