From eb658693a30d10ff39970a5d358af23bcb7a5369 Mon Sep 17 00:00:00 2001 From: Julio Quinteros Pro Date: Tue, 3 Mar 2026 19:51:09 -0300 Subject: [PATCH 1/2] fix: use direct AsyncMock assignment instead of patch.object in JWT tests The patch.object with new_callable=AsyncMock can behave inconsistently across Python versions, causing mock_response.status_code to return a MagicMock instead of the assigned value. Direct assignment is simpler and more reliable. Co-Authored-By: Claude Opus 4.6 --- .../proxy/auth/test_handle_jwt.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/test_litellm/proxy/auth/test_handle_jwt.py b/tests/test_litellm/proxy/auth/test_handle_jwt.py index 3c19097427..391a678982 100644 --- a/tests/test_litellm/proxy/auth/test_handle_jwt.py +++ b/tests/test_litellm/proxy/auth/test_handle_jwt.py @@ -1543,7 +1543,7 @@ async def test_resolve_jwks_url_resolves_oidc_discovery_document(): @pytest.mark.asyncio async def test_resolve_jwks_url_caches_resolved_jwks_uri(): """Resolved jwks_uri is cached — second call does not hit the network.""" - from unittest.mock import AsyncMock, MagicMock, patch + from unittest.mock import AsyncMock, MagicMock from litellm.caching.dual_cache import DualCache @@ -1562,9 +1562,11 @@ async def test_resolve_jwks_url_caches_resolved_jwks_uri(): mock_response.status_code = 200 mock_response.json.return_value = {"jwks_uri": jwks_url} - with patch.object(handler.http_handler, "get", new_callable=AsyncMock, return_value=mock_response) as mock_get: - first = await handler._resolve_jwks_url(discovery_url) - second = await handler._resolve_jwks_url(discovery_url) + mock_get = AsyncMock(return_value=mock_response) + handler.http_handler.get = mock_get + + first = await handler._resolve_jwks_url(discovery_url) + second = await handler._resolve_jwks_url(discovery_url) assert first == jwks_url assert second == jwks_url @@ -1575,7 +1577,7 @@ async def test_resolve_jwks_url_caches_resolved_jwks_uri(): @pytest.mark.asyncio async def test_resolve_jwks_url_raises_if_no_jwks_uri_in_discovery_doc(): """Raise a helpful error if the discovery document has no jwks_uri.""" - from unittest.mock import AsyncMock, MagicMock, patch + from unittest.mock import AsyncMock, MagicMock from litellm.caching.dual_cache import DualCache @@ -1591,9 +1593,10 @@ async def test_resolve_jwks_url_raises_if_no_jwks_uri_in_discovery_doc(): mock_response.status_code = 200 mock_response.json.return_value = {"issuer": "https://example.com"} # no jwks_uri - with patch.object(handler.http_handler, "get", new_callable=AsyncMock, return_value=mock_response): - with pytest.raises(Exception, match="jwks_uri"): - await handler._resolve_jwks_url(discovery_url) + handler.http_handler.get = AsyncMock(return_value=mock_response) + + with pytest.raises(Exception, match="jwks_uri"): + await handler._resolve_jwks_url(discovery_url) # --------------------------------------------------------------------------- From a07d041881e77c6854c3fbf6fb782ed509d69d29 Mon Sep 17 00:00:00 2001 From: Julio Quinteros Pro Date: Tue, 3 Mar 2026 19:56:51 -0300 Subject: [PATCH 2/2] fix: apply same AsyncMock pattern to remaining OIDC discovery test Address Greptile review: test_resolve_jwks_url_resolves_oidc_discovery_document also used the inconsistent patch.object pattern. Co-Authored-By: Claude Opus 4.6 --- tests/test_litellm/proxy/auth/test_handle_jwt.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_litellm/proxy/auth/test_handle_jwt.py b/tests/test_litellm/proxy/auth/test_handle_jwt.py index 391a678982..11939f0fdd 100644 --- a/tests/test_litellm/proxy/auth/test_handle_jwt.py +++ b/tests/test_litellm/proxy/auth/test_handle_jwt.py @@ -1514,7 +1514,7 @@ async def test_resolve_jwks_url_resolves_oidc_discovery_document(): A .well-known/openid-configuration URL should be fetched and its jwks_uri returned. """ - from unittest.mock import AsyncMock, MagicMock, patch + from unittest.mock import AsyncMock, MagicMock from litellm.caching.dual_cache import DualCache @@ -1533,8 +1533,10 @@ async def test_resolve_jwks_url_resolves_oidc_discovery_document(): mock_response.status_code = 200 mock_response.json.return_value = {"jwks_uri": jwks_url, "issuer": "https://..."} - with patch.object(handler.http_handler, "get", new_callable=AsyncMock, return_value=mock_response) as mock_get: - result = await handler._resolve_jwks_url(discovery_url) + mock_get = AsyncMock(return_value=mock_response) + handler.http_handler.get = mock_get + + result = await handler._resolve_jwks_url(discovery_url) assert result == jwks_url mock_get.assert_called_once_with(discovery_url)