1+ import os
2+ from unittest .mock import patch
3+
14import pytest
25from dirty_equals import IsList
36
2225@pytest .mark .skipif (not openai_imports_successful , reason = 'OpenAI not installed' )
2326class TestOpenAI :
2427 async def test_infer_model (self , openai_api_key : str ):
25- model = infer_model ('openai:text-embedding-3-small' )
28+ with patch .dict (os .environ , {'OPENAI_API_KEY' : openai_api_key }):
29+ model = infer_model ('openai:text-embedding-3-small' )
2630 assert isinstance (model , OpenAIEmbeddingModel )
2731 assert model .model_name == 'text-embedding-3-small'
2832 assert model .system == 'openai'
2933 assert model .base_url == 'https://api.openai.com/v1/'
3034
3135 async def test_infer_model_azure (self , openai_api_key : str ):
32- model = infer_model ('azure:text-embedding-3-small' )
36+ with patch .dict (
37+ os .environ ,
38+ {
39+ 'AZURE_OPENAI_API_KEY' : 'azure-openai-api-key' ,
40+ 'AZURE_OPENAI_ENDPOINT' : 'https://project-id.openai.azure.com/' ,
41+ 'OPENAI_API_VERSION' : '2023-03-15-preview' ,
42+ },
43+ ):
44+ model = infer_model ('azure:text-embedding-3-small' )
3345 assert isinstance (model , OpenAIEmbeddingModel )
3446 assert model .model_name == 'text-embedding-3-small'
3547 assert model .system == 'azure'
@@ -55,7 +67,8 @@ async def test_bulk(self, openai_api_key: str):
5567@pytest .mark .skipif (not cohere_imports_successful , reason = 'Cohere not installed' )
5668class TestCohere :
5769 async def test_infer_model (self , co_api_key : str ):
58- model = infer_model ('cohere:embed-v4.0' )
70+ with patch .dict (os .environ , {'CO_API_KEY' : co_api_key }):
71+ model = infer_model ('cohere:embed-v4.0' )
5972 assert isinstance (model , CohereEmbeddingModel )
6073 assert model .model_name == 'embed-v4.0'
6174 assert model .system == 'cohere'
0 commit comments