fix(test): add missing mock for get_vertex_ai_credentials#21274
fix(test): add missing mock for get_vertex_ai_credentials#21274
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Add missing mock for get_vertex_ai_credentials in test_validate_environment_with_optional_params to prevent it from trying to load the fake credential file "path/to/credentials.json". The test was failing with: "Exception: Unable to load vertex credentials from environment. Got=path/to/credentials.json" The test test_validate_environment already has this mock (line 92), but test_validate_environment_with_optional_params was missing it. Adding the same mock pattern: patch.object(self.config, 'get_vertex_ai_credentials', return_value=None) Test now passes ✅ Related: test was failing on PR #21217, but NOT caused by PR #21217 (which only modifies test_anthropic_structured_output.py). This is a missing mock in the test. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
a4cbb83 to
00bb393
Compare
Greptile SummaryThis PR adds a However,
Confidence Score: 3/5
|
| Filename | Overview |
|---|---|
| tests/test_litellm/llms/vertex_ai/rerank/test_vertex_ai_rerank_transformation.py | Adds a mock for get_vertex_ai_credentials in test_validate_environment_with_optional_params, but validate_environment actually calls safe_get_vertex_ai_credentials — the mock targets the wrong method and has no effect. The test passes because _ensure_access_token is already mocked via the @patch decorator. |
Sequence Diagram
sequenceDiagram
participant Test as Test Method
participant Config as VertexAIRerankConfig
participant SafeGet as safe_get_vertex_ai_credentials
participant GetCreds as get_vertex_ai_credentials
participant EnsureToken as _ensure_access_token
Note over GetCreds: MOCKED but never called
Note over EnsureToken: MOCKED via decorator
Test->>Config: validate_environment(optional_params)
Config->>SafeGet: safe_get_vertex_ai_credentials(params)
SafeGet-->>Config: credential string from optional_params
Config->>EnsureToken: called with credential string
EnsureToken-->>Config: mocked return value
Config-->>Test: headers dict
Last reviewed commit: a4cbb83
| assert headers == expected_headers | ||
|
|
||
| # Mock get_vertex_ai_credentials to prevent it from trying to load the fake credential file | ||
| with patch.object(self.config, 'get_vertex_ai_credentials', return_value=None): |
There was a problem hiding this comment.
Mock targets wrong method
validate_environment (in transformation.py:80) calls self.safe_get_vertex_ai_credentials(litellm_params), not self.get_vertex_ai_credentials(...). Since safe_get_vertex_ai_credentials is the method actually invoked, this patch.object for get_vertex_ai_credentials has no effect — it mocks a method that is never called in this code path.
The test already works because _ensure_access_token is mocked via the @patch decorator on the test method, which intercepts the call before any real credential loading occurs.
If the intent is to prevent safe_get_vertex_ai_credentials from returning the fake credential string, the mock should target that method instead:
| with patch.object(self.config, 'get_vertex_ai_credentials', return_value=None): | |
| with patch.object(self.config, 'safe_get_vertex_ai_credentials', return_value=None): |
Note: the same pattern may need to be applied to test_validate_environment_preserves_optional_params_for_get_complete_url (line 476) which also passes fake credentials without mocking.
|
Closing this PR. The test failures were due to environment variable pollution from other tests, which was already fixed by PR #21268 that adds setup_method/teardown_method to clean environment variables. As Greptile correctly identified, the mock added in this PR is ineffective - it mocks The tests now pass on main branch in isolation, confirming the environment cleanup in #21268 resolved the issue. |
Summary
Fixes test failure by adding missing mock for
get_vertex_ai_credentials.Problem
Test
test_validate_environment_with_optional_paramswas failing with:The test passes
"path/to/credentials.json"as fake credentials, but the code tries to load this file for real, which:Root Cause
The test
test_validate_environment(line 92) correctly mocksget_vertex_ai_credentials:But
test_validate_environment_with_optional_paramswas missing this mock, causing it to try loading the fake credential file for real.Solution
Added the same mock pattern to
test_validate_environment_with_optional_params:Testing
pytest tests/.../test_vertex_ai_rerank_transformation.py::TestVertexAIRerankTransform::test_validate_environment_with_optional_params -v ======================== 1 passed in 0.18s ========================Related
This test failure was reported on PR #21217, but NOT caused by PR #21217 (which only modifies Anthropic structured output tests). This is a missing mock in the test itself.
🤖 Generated with Claude Code