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:
@@ -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 ─────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user