mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-16 17:55:26 -04:00
fix(tests): isolate webhook task reference imports
Isolate src.database/src.webhook_manager imports in test_webhook_task_refs so collection does not leak stubbed modules into later tests.
This commit is contained in:
@@ -7,16 +7,20 @@ releases it on completion.
|
|||||||
"""
|
"""
|
||||||
import asyncio
|
import asyncio
|
||||||
import sys
|
import sys
|
||||||
|
import types
|
||||||
|
|
||||||
# webhook_manager does `from src.database import SessionLocal, Webhook` at import
|
from tests.helpers.import_state import clear_module, preserve_import_state
|
||||||
# time. The shared test harness stubs src.database without Webhook, so ensure the
|
|
||||||
# attribute exists before importing the manager. These tests never touch the DB
|
# Import the manager against a private database stub, then restore both modules
|
||||||
# (the manager is built via __new__), so a placeholder class is sufficient.
|
# so collection does not mutate shared import state.
|
||||||
_db = sys.modules.get("src.database")
|
with preserve_import_state("src.database", "src.webhook_manager"):
|
||||||
if _db is not None and not hasattr(_db, "Webhook"):
|
clear_module("src.database")
|
||||||
|
clear_module("src.webhook_manager")
|
||||||
|
_db = types.ModuleType("src.database")
|
||||||
|
_db.SessionLocal = object()
|
||||||
_db.Webhook = type("Webhook", (), {})
|
_db.Webhook = type("Webhook", (), {})
|
||||||
|
sys.modules["src.database"] = _db
|
||||||
from src.webhook_manager import WebhookManager # noqa: E402
|
from src.webhook_manager import WebhookManager
|
||||||
|
|
||||||
|
|
||||||
def test_spawn_tracked_holds_then_releases_reference():
|
def test_spawn_tracked_holds_then_releases_reference():
|
||||||
|
|||||||
Reference in New Issue
Block a user