fix(test): add autouse fixture to reset worker_app.db module between tests

Add _reset_worker_app_db pytest fixture with autouse=True to prevent
mock pollution from leaking between tests. This fixes the flaky
test_batch_download_session_closed test that would fail when running
the full test suite due to worker_app.db being replaced with a
MagicMock from a previous test.
This commit is contained in:
xiaoxia
2026-08-13 20:43:13 +08:00
committed by root
parent 0301370dd8
commit 71ca3a0d6e
+14
View File
@@ -13,6 +13,20 @@ from unittest.mock import MagicMock, patch
import pytest
@pytest.fixture(autouse=True)
def _reset_worker_app_db():
"""Prevent mock pollution from leaking between tests."""
import importlib
import sys
# Save original module reference
original = sys.modules.get("worker_app.db")
yield
# Restore original module after each test
if original is not None:
sys.modules["worker_app.db"] = original
# ── Fake repository ─────────────────────────────────────────────────────────