mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
test(mcp): reload mcp_server_manager alongside utils in identity-env fixture
_env_and_reload() in test_mcp_server_identity_env.py reloads utils and mcp_management_endpoints, but not mcp_server_manager. mcp_server_manager does `from ...utils import MCPMissingUserEnvVarsError` at module load time, so after this fixture reloads utils, mcp_server_manager still raises the pre-reload class object. Any test in the same worker that runs afterward and asserts on that exception via a fresh utils lookup (pytest.raises(getattr(utils, ...))) fails to match, since the two class objects are no longer identical despite sharing a name. Reproduced deterministically by running test_mcp_server_identity_env.py followed by the affected tests in the same process — no -n/xdist needed. Reload mcp_server_manager in the same fixture, matching the pattern already used correctly in test_mcp_server_manager.py.
This commit is contained in:
parent
1a8cd8a078
commit
2dae453ab9
1 changed files with 10 additions and 0 deletions
|
|
@ -18,6 +18,7 @@ pytest.importorskip("mcp")
|
|||
|
||||
UTILS_MODULE = "litellm.proxy._experimental.mcp_server.utils"
|
||||
MGMT_MODULE = "litellm.proxy.management_endpoints.mcp_management_endpoints"
|
||||
MANAGER_MODULE = "litellm.proxy._experimental.mcp_server.mcp_server_manager"
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
|
@ -32,8 +33,17 @@ def _env_and_reload(**env):
|
|||
os.environ[key] = value
|
||||
|
||||
def _reload():
|
||||
# utils must reload first: MGMT_MODULE and MANAGER_MODULE both do
|
||||
# ``from ...utils import X`` at module load time, so reloading them
|
||||
# afterward re-binds those names to the fresh utils classes/values.
|
||||
# Every module with a frozen import from utils needs to be listed
|
||||
# here -- mcp_server_manager.py imports MCPMissingUserEnvVarsError
|
||||
# this way, and a stale reference there causes
|
||||
# pytest.raises(_u("MCPMissingUserEnvVarsError")) to stop matching
|
||||
# in any test that runs after this one reloads utils.
|
||||
utils = importlib.reload(importlib.import_module(UTILS_MODULE))
|
||||
mgmt = importlib.reload(importlib.import_module(MGMT_MODULE))
|
||||
importlib.reload(importlib.import_module(MANAGER_MODULE))
|
||||
return utils, mgmt
|
||||
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue