11import asyncio
2- import os
32import time
43from unittest import mock
54from unittest .mock import AsyncMock
@@ -131,9 +130,9 @@ def module_start_status_message(self, instance, inputs):
131130 assert status_messages [2 ].message == "Predict starting!"
132131
133132
134- @pytest .mark .skipif ( not os . getenv ( "OPENAI_API_KEY" ), reason = "OpenAI API key not found in environment variables" )
133+ @pytest .mark .llm_call
135134@pytest .mark .anyio
136- async def test_stream_listener_chat_adapter ():
135+ async def test_stream_listener_chat_adapter (lm_for_test ):
137136 class MyProgram (dspy .Module ):
138137 def __init__ (self ):
139138 self .predict1 = dspy .Predict ("question->answer" )
@@ -154,7 +153,7 @@ def __call__(self, x: str, **kwargs):
154153 include_final_prediction_in_output_stream = False ,
155154 )
156155 # Turn off the cache to ensure the stream is produced.
157- with dspy .context (lm = dspy .LM ("openai/gpt-4o-mini" , cache = False )):
156+ with dspy .context (lm = dspy .LM (lm_for_test , cache = False )):
158157 output = program (x = "why did a chicken cross the kitchen?" )
159158 all_chunks = []
160159 async for value in output :
@@ -194,9 +193,9 @@ async def acall(self, x: str):
194193 assert status_messages [1 ].message == "Tool calling finished! Querying the LLM with tool calling results..."
195194
196195
197- @pytest .mark .skipif ( not os . getenv ( "OPENAI_API_KEY" ), reason = "OpenAI API key not found in environment variables" )
196+ @pytest .mark .llm_call
198197@pytest .mark .anyio
199- async def test_stream_listener_json_adapter ():
198+ async def test_stream_listener_json_adapter (lm_for_test ):
200199 class MyProgram (dspy .Module ):
201200 def __init__ (self ):
202201 self .predict1 = dspy .Predict ("question->answer" )
@@ -217,7 +216,7 @@ def __call__(self, x: str, **kwargs):
217216 include_final_prediction_in_output_stream = False ,
218217 )
219218 # Turn off the cache to ensure the stream is produced.
220- with dspy .context (lm = dspy .LM ("openai/gpt-4o-mini" , cache = False ), adapter = dspy .JSONAdapter ()):
219+ with dspy .context (lm = dspy .LM (lm_for_test , cache = False ), adapter = dspy .JSONAdapter ()):
221220 output = program (x = "why did a chicken cross the kitchen?" )
222221 all_chunks = []
223222 async for value in output :
@@ -261,8 +260,8 @@ async def gpt_4o_mini_stream(*args, **kwargs):
261260 assert all_chunks [0 ].chunk == "How are you doing?"
262261
263262
264- @pytest .mark .skipif ( not os . getenv ( "OPENAI_API_KEY" ), reason = "OpenAI API key not found in environment variables" )
265- def test_sync_streaming ():
263+ @pytest .mark .llm_call
264+ def test_sync_streaming (lm_for_test ):
266265 class MyProgram (dspy .Module ):
267266 def __init__ (self ):
268267 self .predict1 = dspy .Predict ("question->answer" )
@@ -284,7 +283,7 @@ def __call__(self, x: str, **kwargs):
284283 async_streaming = False ,
285284 )
286285 # Turn off the cache to ensure the stream is produced.
287- with dspy .context (lm = dspy .LM ("openai/gpt-4o-mini" , cache = False )):
286+ with dspy .context (lm = dspy .LM (lm_for_test , cache = False )):
288287 output = program (x = "why did a chicken cross the kitchen?" )
289288 all_chunks = []
290289 for value in output :
0 commit comments