@@ -3340,7 +3340,11 @@ def test_streaming_responses_api_ttft(
33403340@pytest .mark .asyncio
33413341@pytest .mark .skipif (SKIP_RESPONSES_TESTS , reason = "Responses API not available" )
33423342async def test_streaming_responses_api_ttft_async (
3343- sentry_init , capture_events , async_iterator
3343+ sentry_init ,
3344+ capture_events ,
3345+ get_model_response ,
3346+ async_iterator ,
3347+ server_side_event_chunks ,
33443348):
33453349 """
33463350 Test that async streaming responses API captures time-to-first-token (TTFT).
@@ -3352,19 +3356,24 @@ async def test_streaming_responses_api_ttft_async(
33523356 events = capture_events ()
33533357
33543358 client = AsyncOpenAI (api_key = "z" )
3355- returned_stream = AsyncStream ( cast_to = None , response = None , client = client )
3356- returned_stream . _iterator = async_iterator (EXAMPLE_RESPONSES_STREAM )
3357- client . responses . _post = AsyncMock ( return_value = returned_stream )
3359+ returned_stream = get_model_response (
3360+ async_iterator (server_side_event_chunks ( EXAMPLE_RESPONSES_STREAM ) )
3361+ )
33583362
3359- with start_transaction (name = "openai tx" ):
3360- response_stream = await client .responses .create (
3361- model = "some-model" ,
3362- input = "hello" ,
3363- stream = True ,
3364- )
3365- # Consume the stream
3366- async for _ in response_stream :
3367- pass
3363+ with mock .patch .object (
3364+ client .chat ._client ._client ,
3365+ "send" ,
3366+ return_value = returned_stream ,
3367+ ):
3368+ with start_transaction (name = "openai tx" ):
3369+ response_stream = await client .responses .create (
3370+ model = "some-model" ,
3371+ input = "hello" ,
3372+ stream = True ,
3373+ )
3374+ # Consume the stream
3375+ async for _ in response_stream :
3376+ pass
33683377
33693378 (tx ,) = events
33703379 span = tx ["spans" ][0 ]
0 commit comments