fix(test): remove redundant outer patch in cache invalidation test

The outer patch on the module-level attribute has no effect since
_reset_budget_for_enduser uses a lazy local import. Only the
sys.modules patch intercepts the import.
This commit is contained in:
Atharva Jaiswal 2026-03-28 23:11:27 +05:30
parent 434f51d51a
commit e27bd82264

View file

@ -269,23 +269,20 @@ def test_reset_budget_for_enduser_invalidates_cache():
mock_cache.async_delete_cache = AsyncMock()
async def _run():
with patch(
"litellm.proxy.common_utils.reset_budget_job.user_api_key_cache",
mock_cache,
create=True,
# Patch sys.modules so the lazy import inside _reset_budget_for_enduser
# (`from litellm.proxy.proxy_server import user_api_key_cache`)
# picks up our mock cache.
with patch.dict(
"sys.modules",
{
"litellm.proxy.proxy_server": type(
"module", (), {"user_api_key_cache": mock_cache}
)()
},
):
# Patch the import inside the function
with patch.dict(
"sys.modules",
{
"litellm.proxy.proxy_server": type(
"module", (), {"user_api_key_cache": mock_cache}
)()
},
):
result = await ResetBudgetJob._reset_budget_for_enduser(
enduser=test_enduser
)
result = await ResetBudgetJob._reset_budget_for_enduser(
enduser=test_enduser
)
assert result is not None
assert result.spend == 0.0