refactor(tests): reuse import-state helper in auth tests
Test-only refactor continuing #2523. Replaces a repeated core.auth cache eviction pattern in three auth tests with the shared clear_module helper, preserving behavior.
This commit is contained in:
committed by
GitHub
parent
f9e1d38cc2
commit
4f0133b8c3
@@ -11,6 +11,8 @@ from unittest.mock import MagicMock
|
|||||||
import pytest
|
import pytest
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
|
|
||||||
|
from tests.helpers.import_state import clear_module
|
||||||
|
|
||||||
|
|
||||||
def _real_core_package():
|
def _real_core_package():
|
||||||
root = Path(__file__).resolve().parent.parent
|
root = Path(__file__).resolve().parent.parent
|
||||||
@@ -20,9 +22,7 @@ def _real_core_package():
|
|||||||
core = types.ModuleType("core")
|
core = types.ModuleType("core")
|
||||||
sys.modules["core"] = core
|
sys.modules["core"] = core
|
||||||
core.__path__ = [core_path]
|
core.__path__ = [core_path]
|
||||||
if hasattr(core, "auth"):
|
clear_module("core.auth")
|
||||||
delattr(core, "auth")
|
|
||||||
sys.modules.pop("core.auth", None)
|
|
||||||
return core
|
return core
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ from pathlib import Path
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from tests.helpers.import_state import clear_module
|
||||||
|
|
||||||
|
|
||||||
def _real_core_package():
|
def _real_core_package():
|
||||||
root = Path(__file__).resolve().parent.parent
|
root = Path(__file__).resolve().parent.parent
|
||||||
@@ -22,9 +24,7 @@ def _real_core_package():
|
|||||||
core = types.ModuleType("core")
|
core = types.ModuleType("core")
|
||||||
sys.modules["core"] = core
|
sys.modules["core"] = core
|
||||||
core.__path__ = [core_path]
|
core.__path__ = [core_path]
|
||||||
if hasattr(core, "auth"):
|
clear_module("core.auth")
|
||||||
delattr(core, "auth")
|
|
||||||
sys.modules.pop("core.auth", None)
|
|
||||||
return core
|
return core
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ from unittest.mock import MagicMock
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from tests.helpers.import_state import clear_module
|
||||||
|
|
||||||
|
|
||||||
def _real_core_package():
|
def _real_core_package():
|
||||||
root = Path(__file__).resolve().parent.parent
|
root = Path(__file__).resolve().parent.parent
|
||||||
@@ -23,9 +25,7 @@ def _real_core_package():
|
|||||||
core = types.ModuleType("core")
|
core = types.ModuleType("core")
|
||||||
sys.modules["core"] = core
|
sys.modules["core"] = core
|
||||||
core.__path__ = [core_path]
|
core.__path__ = [core_path]
|
||||||
if hasattr(core, "auth"):
|
clear_module("core.auth")
|
||||||
delattr(core, "auth")
|
|
||||||
sys.modules.pop("core.auth", None)
|
|
||||||
return core
|
return core
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user