test: monkeypatch OpenAI API key in some unit tests (#9173)

This commit is contained in:
Stefano Fiorucci 2025-04-04 13:33:22 +02:00 committed by GitHub
parent d977b262b6
commit c6df8d2c7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 3 deletions

View File

@ -80,7 +80,8 @@ class TestContextRelevanceEvaluator:
assert component._chat_generator.client.api_key == "test-api-key"
assert component._chat_generator.generation_kwargs == {"response_format": {"type": "json_object"}, "seed": 42}
def test_init_with_chat_generator(self):
def test_init_with_chat_generator(self, monkeypatch):
monkeypatch.setenv("OPENAI_API_KEY", "test-api-key")
chat_generator = OpenAIChatGenerator(generation_kwargs={"response_format": {"type": "json_object"}, "seed": 42})
component = ContextRelevanceEvaluator(chat_generator=chat_generator)

View File

@ -100,7 +100,8 @@ class TestFaithfulnessEvaluator:
assert component._chat_generator.client.api_key == "test-api-key"
assert component._chat_generator.generation_kwargs == {"response_format": {"type": "json_object"}, "seed": 42}
def test_init_with_chat_generator(self):
def test_init_with_chat_generator(self, monkeypatch):
monkeypatch.setenv("OPENAI_API_KEY", "test-api-key")
chat_generator = OpenAIChatGenerator(generation_kwargs={"response_format": {"type": "json_object"}, "seed": 42})
component = FaithfulnessEvaluator(chat_generator=chat_generator)

View File

@ -98,7 +98,8 @@ class TestDeserializeDocumentStoreInInitParamsInplace:
class TestDeserializeChatGeneratorInplace:
def test_deserialize_chatgenerator_inplace(self):
def test_deserialize_chatgenerator_inplace(self, monkeypatch):
monkeypatch.setenv("OPENAI_API_KEY", "test-api-key")
chat_generator = OpenAIChatGenerator()
data = {"chat_generator": chat_generator.to_dict()}