mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
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 <ishaan-jaff@users.noreply.github.com>
This commit is contained in:
parent
dcf83903e5
commit
eb4a280e59
1 changed files with 8 additions and 2 deletions
|
|
@ -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,
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue