[Fix] WatsonX Tests Failing on CI Due to Missing Env Vars - #24814
Conversation
Tests are fully mocked but require WATSONX_URL and WATSONX_PROJECT_ID to pass provider validation before reaching the mocked HTTP client. Add an autouse fixture with dummy values and clear WATSONX_ZENAPIKEY/ WATSONX_TOKEN to prevent env leakage from dotenv. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR fixes WatsonX tests in The fix adds a single
The approach is clean: individual tests that need to override these values (e.g., Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| tests/llm_translation/test_watsonx.py | Adds an autouse pytest fixture that injects dummy WATSONX_URL/WATSONX_PROJECT_ID env vars and clears WATSONX_ZENAPIKEY/WATSONX_TOKEN to allow fully-mocked tests to reach the mocked HTTP client on CI without real credentials. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[pytest test starts] --> B[autouse fixture: watsonx_env_vars]
B --> B1[monkeypatch.setenv WATSONX_URL]
B1 --> B2[monkeypatch.setenv WATSONX_PROJECT_ID]
B2 --> B3[monkeypatch.delenv WATSONX_ZENAPIKEY]
B3 --> B4[monkeypatch.delenv WATSONX_TOKEN]
B4 --> C{Test type}
C -- token env var test --> D[test sets WATSONX_ZENAPIKEY or WATSONX_TOKEN]
C -- space_id test --> E[test deletes WATSONX_PROJECT_ID, sets WATSONX_SPACE_ID]
C -- other tests --> F[proceed with WATSONX_URL + WATSONX_PROJECT_ID set]
D --> G[WatsonX provider passes validation]
E --> G
F --> G
G --> H[mocked HTTP client is reached]
H --> I[mock_post.call_count == 1 assertion passes]
Reviews (1): Last reviewed commit: "[Fix] WatsonX tests failing on CI due to..." | Re-trigger Greptile
…lcini [Fix] WatsonX Tests Failing on CI Due to Missing Env Vars
Summary
Failure Path (Before Fix)
WatsonX tests in
tests/llm_translation/test_watsonx.pyfail on CI withassert mock_post.call_count == 0 == 1. The tests are fully mocked but the WatsonX provider requiresWATSONX_URLandWATSONX_PROJECT_IDenv vars to pass validation before reaching the mocked HTTP client. Without them, a validation error is raised and silently swallowed by the fixture'sexceptblock.Fix
Added an
autousefixture that sets dummyWATSONX_URLandWATSONX_PROJECT_IDviamonkeypatch, and clearsWATSONX_ZENAPIKEY/WATSONX_TOKENto prevent env leakage from.envfiles loaded bydotenv.load_dotenv(). No real API keys or CI/CD env var changes needed.Testing
All 11 tests in
tests/llm_translation/test_watsonx.pypass locally.Type
🐛 Bug Fix
✅ Test