From 62ac8cee8ef5bde0ab35cc35a9daafb0556c7205 Mon Sep 17 00:00:00 2001 From: Julio Quinteros Pro Date: Sun, 15 Feb 2026 19:19:43 -0300 Subject: [PATCH] fix(test): add environment cleanup for Vertex AI Qwen tests Add autouse pytest fixture to clear Google/Vertex AI environment variables before each test, preventing authentication errors in CI. Previous tests may set GOOGLE_APPLICATION_CREDENTIALS or other Vertex environment variables and not clean them up, causing this test to attempt real Google authentication instead of using mocks. This fix: - Adds clean_vertex_env fixture with autouse=True - Saves and clears Google/Vertex env vars before each test - Restores them after each test - Prevents "AuthenticationError: Request had invalid authentication credentials" (401) in CI when run with other tests Same fix pattern as PR #21268 (rerank) and PR #21272 (GPT-OSS). Related: test was failing on PR #21217, but NOT caused by PR #21217 (which only modifies test_anthropic_structured_output.py). This is another test isolation issue. Co-Authored-By: Claude Sonnet 4.5 --- .../test_vertex_ai_qwen_global_endpoint.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) 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 6310431813b..bdf391ba5b4 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 @@ -24,6 +24,30 @@ from litellm.types.llms.vertex_ai import VertexPartnerProvider +@pytest.fixture(autouse=True) +def clean_vertex_env(): + """Clear Google/Vertex AI environment variables before each test to prevent test isolation issues.""" + saved_env = {} + env_vars_to_clear = [ + "GOOGLE_APPLICATION_CREDENTIALS", + "GOOGLE_CLOUD_PROJECT", + "VERTEXAI_PROJECT", + "VERTEX_PROJECT", + "VERTEX_LOCATION", + "VERTEX_AI_PROJECT", + ] + for var in env_vars_to_clear: + if var in os.environ: + saved_env[var] = os.environ[var] + del os.environ[var] + + yield + + # Restore saved environment variables + for var, value in saved_env.items(): + os.environ[var] = value + + class TestQwenGlobalOnlyDetection: """Test that Qwen models are correctly identified as global-only."""