From eb4a280e59e8dd5d1b1daefd1d692a1dac468e82 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 28 Feb 2026 07:55:08 +0000 Subject: [PATCH] Fix vertex AI qwen global endpoint test to mock vertexai module import The test_vertex_ai_qwen_global_endpoint_url test was failing because the VertexAIPartnerModels.completion() method tries to 'import vertexai' before any of the mocked code runs. In environments without google-cloud-aiplatform installed, this import fails with a VertexAIError(status_code=400). Fix by: - Adding patch.dict('sys.modules', {'vertexai': MagicMock()}) to mock the vertexai module import - Adding vertex_ai_location parameter to the acompletion call for completeness Co-authored-by: Ishaan Jaff --- .../qwen/test_vertex_ai_qwen_global_endpoint.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_litellm/llms/vertex_ai/vertex_ai_partner_models/qwen/test_vertex_ai_qwen_global_endpoint.py b/tests/test_litellm/llms/vertex_ai/vertex_ai_partner_models/qwen/test_vertex_ai_qwen_global_endpoint.py index bdf391ba5b4..dafd58b06d8 100644 --- a/tests/test_litellm/llms/vertex_ai/vertex_ai_partner_models/qwen/test_vertex_ai_qwen_global_endpoint.py +++ b/tests/test_litellm/llms/vertex_ai/vertex_ai_partner_models/qwen/test_vertex_ai_qwen_global_endpoint.py @@ -10,7 +10,7 @@ These tests verify that: import json import os import sys -from unittest.mock import MagicMock, patch +from unittest.mock import MagicMock, patch, AsyncMock import pytest @@ -210,7 +210,12 @@ async def test_vertex_ai_qwen_global_endpoint_url(): async def mock_post_func(*args, **kwargs): return mock_response - with patch.object(client, "post", side_effect=mock_post_func) as mock_post, patch.object( + mock_vertexai = MagicMock() + mock_vertexai.preview = MagicMock() + + with patch.dict("sys.modules", {"vertexai": mock_vertexai}), patch.object( + client, "post", side_effect=mock_post_func + ) as mock_post, patch.object( VertexLLM, "_ensure_access_token", return_value=("fake-token", "test-project") ), patch( "litellm.llms.vertex_ai.vertex_llm_base.is_global_only_vertex_model", @@ -220,6 +225,7 @@ async def test_vertex_ai_qwen_global_endpoint_url(): model="vertex_ai/qwen/qwen3-next-80b-a3b-instruct-maas", messages=[{"role": "user", "content": "Hello"}], vertex_ai_project="test-project", + vertex_ai_location="us-central1", client=client, )