fix(test): add environment cleanup for Vertex AI GPT-OSS 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" in CI when run with other tests

Test makes real API calls in CI without this fix, gets 401 error.
Locally fails with "No module named 'vertexai'" (expected).

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 <noreply@anthropic.com>
This commit is contained in:
Julio Quinteros Pro 2026-02-15 19:16:46 -03:00
parent e162410294
commit cf11867159

View file

@ -16,6 +16,30 @@ from litellm.llms.vertex_ai.vertex_ai_partner_models.gpt_oss.transformation impo
)
@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 TestVertexAIGPTOSSTransformation:
"""Test class for VertexAI GPT-OSS transformation functionality."""