fix(tests): isolate env in resolve_google_judge_api_key test
The second assertion in test_resolve_google_judge_api_key_prefers_google_key ran outside the mock.patch.dict context. When GOOGLE_API_KEY or GEMINI_API_KEY is set in the real environment, os.environ takes precedence over the config dict fallback and the test fails. Wrap the assertion in its own mock.patch.dict scope that clears the three relevant env vars so the test passes regardless of the developer's env. This contribution was developed with AI assistance (Claude Code).
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
@@ -99,7 +100,10 @@ class EvaluatorV3Tests(unittest.TestCase):
|
|||||||
def test_resolve_google_judge_api_key_prefers_google_key(self):
|
def test_resolve_google_judge_api_key_prefers_google_key(self):
|
||||||
with mock.patch.dict("os.environ", {"GOOGLE_API_KEY": "google", "GEMINI_API_KEY": "gemini"}, clear=False):
|
with mock.patch.dict("os.environ", {"GOOGLE_API_KEY": "google", "GEMINI_API_KEY": "gemini"}, clear=False):
|
||||||
self.assertEqual("google", evaluator.resolve_google_judge_api_key({}))
|
self.assertEqual("google", evaluator.resolve_google_judge_api_key({}))
|
||||||
self.assertEqual("fallback", evaluator.resolve_google_judge_api_key({"GOOGLE_GENAI_API_KEY": "fallback"}))
|
with mock.patch.dict("os.environ", {k: "" for k in ("GOOGLE_API_KEY", "GEMINI_API_KEY", "GOOGLE_GENAI_API_KEY")}, clear=False):
|
||||||
|
for k in ("GOOGLE_API_KEY", "GEMINI_API_KEY", "GOOGLE_GENAI_API_KEY"):
|
||||||
|
os.environ.pop(k, None)
|
||||||
|
self.assertEqual("fallback", evaluator.resolve_google_judge_api_key({"GOOGLE_GENAI_API_KEY": "fallback"}))
|
||||||
|
|
||||||
def test_extract_gemini_text_raises_when_missing(self):
|
def test_extract_gemini_text_raises_when_missing(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|||||||
Reference in New Issue
Block a user