@@ -98,9 +98,10 @@ def _assert_response_content(span, response, log_exporter):
9898 span .attributes [GenAIAttributes .GEN_AI_INPUT_MESSAGES ],
9999 USER_ONLY_EXPECTED_INPUT_MESSAGES ,
100100 )
101- assert json .loads (
102- span .attributes [GenAIAttributes .GEN_AI_SYSTEM_INSTRUCTIONS ]
103- ) == EXPECTED_SYSTEM_INSTRUCTIONS
101+ assert (
102+ json .loads (span .attributes [GenAIAttributes .GEN_AI_SYSTEM_INSTRUCTIONS ])
103+ == EXPECTED_SYSTEM_INSTRUCTIONS
104+ )
104105 assert_messages_attribute (
105106 span .attributes [GenAIAttributes .GEN_AI_OUTPUT_MESSAGES ],
106107 format_simple_expected_output_message (response .output_text ),
@@ -129,7 +130,9 @@ def _assert_request_attrs(
129130 == max_tokens
130131 )
131132 if output_type is not None :
132- assert span .attributes [GenAIAttributes .GEN_AI_OUTPUT_TYPE ] == output_type
133+ assert (
134+ span .attributes [GenAIAttributes .GEN_AI_OUTPUT_TYPE ] == output_type
135+ )
133136
134137
135138def _collect_completed_response (stream ):
@@ -206,17 +209,20 @@ def test_responses_create_basic(
206209 response .usage .output_tokens ,
207210 response_service_tier = getattr (response , "service_tier" , None ),
208211 )
209- assert (
210- span .attributes [GenAIAttributes .GEN_AI_RESPONSE_FINISH_REASONS ]
211- == ("stop" ,)
212+ assert span .attributes [GenAIAttributes .GEN_AI_RESPONSE_FINISH_REASONS ] == (
213+ "stop" ,
212214 )
213215 assert GenAIAttributes .GEN_AI_INPUT_MESSAGES not in span .attributes
214216 assert GenAIAttributes .GEN_AI_OUTPUT_MESSAGES not in span .attributes
215217
216218
217219@pytest .mark .vcr ()
218220def test_responses_create_captures_content (
219- request , span_exporter , log_exporter , openai_client , instrument_with_content
221+ request ,
222+ span_exporter ,
223+ log_exporter ,
224+ openai_client ,
225+ instrument_with_content ,
220226):
221227 _skip_if_not_latest ()
222228
@@ -327,7 +333,9 @@ def test_responses_create_stop_reason(
327333 )
328334
329335
330- def test_responses_create_connection_error (span_exporter , instrument_no_content ):
336+ def test_responses_create_connection_error (
337+ span_exporter , instrument_no_content
338+ ):
331339 _skip_if_not_latest ()
332340
333341 client = OpenAI (base_url = "http://localhost:4242" )
@@ -340,7 +348,9 @@ def test_responses_create_connection_error(span_exporter, instrument_no_content)
340348 )
341349
342350 (span ,) = span_exporter .get_finished_spans ()
343- assert span .attributes [GenAIAttributes .GEN_AI_REQUEST_MODEL ] == DEFAULT_MODEL
351+ assert (
352+ span .attributes [GenAIAttributes .GEN_AI_REQUEST_MODEL ] == DEFAULT_MODEL
353+ )
344354 assert span .attributes [ServerAttributes .SERVER_ADDRESS ] == "localhost"
345355 assert span .attributes [ServerAttributes .SERVER_PORT ] == 4242
346356 assert span .attributes [ErrorAttributes .ERROR_TYPE ] == "APIConnectionError"
@@ -359,7 +369,9 @@ def test_responses_create_api_error(
359369 )
360370
361371 (span ,) = span_exporter .get_finished_spans ()
362- assert span .attributes [GenAIAttributes .GEN_AI_REQUEST_MODEL ] == INVALID_MODEL
372+ assert (
373+ span .attributes [GenAIAttributes .GEN_AI_REQUEST_MODEL ] == INVALID_MODEL
374+ )
363375 assert (
364376 span .attributes [ErrorAttributes .ERROR_TYPE ]
365377 == type (exc_info .value ).__name__
@@ -415,7 +427,11 @@ def test_responses_create_streaming_aggregates_cache_tokens(
415427
416428@pytest .mark .vcr ()
417429def test_responses_create_streaming_captures_content (
418- request , span_exporter , log_exporter , openai_client , instrument_with_content
430+ request ,
431+ span_exporter ,
432+ log_exporter ,
433+ openai_client ,
434+ instrument_with_content ,
419435):
420436 _skip_if_not_latest ()
421437
@@ -448,7 +464,9 @@ def test_responses_create_streaming_iteration(
448464 assert len (events ) > 0
449465
450466 (span ,) = span_exporter .get_finished_spans ()
451- assert span .attributes [GenAIAttributes .GEN_AI_REQUEST_MODEL ] == DEFAULT_MODEL
467+ assert (
468+ span .attributes [GenAIAttributes .GEN_AI_REQUEST_MODEL ] == DEFAULT_MODEL
469+ )
452470 assert GenAIAttributes .GEN_AI_RESPONSE_ID in span .attributes
453471 assert GenAIAttributes .GEN_AI_RESPONSE_MODEL in span .attributes
454472
@@ -488,7 +506,9 @@ def test_responses_create_streaming_connection_error(
488506 )
489507
490508 (span ,) = span_exporter .get_finished_spans ()
491- assert span .attributes [GenAIAttributes .GEN_AI_REQUEST_MODEL ] == DEFAULT_MODEL
509+ assert (
510+ span .attributes [GenAIAttributes .GEN_AI_REQUEST_MODEL ] == DEFAULT_MODEL
511+ )
492512 assert span .attributes [ErrorAttributes .ERROR_TYPE ] == "APIConnectionError"
493513
494514
@@ -559,13 +579,17 @@ def __getattr__(self, name):
559579 stream , "stream" , ErrorInjectingStreamDelegate (stream .stream )
560580 )
561581
562- with pytest .raises (ConnectionError , match = "connection reset during stream" ):
582+ with pytest .raises (
583+ ConnectionError , match = "connection reset during stream"
584+ ):
563585 with stream :
564586 for _ in stream :
565587 pass
566588
567589 (span ,) = span_exporter .get_finished_spans ()
568- assert span .attributes [GenAIAttributes .GEN_AI_REQUEST_MODEL ] == DEFAULT_MODEL
590+ assert (
591+ span .attributes [GenAIAttributes .GEN_AI_REQUEST_MODEL ] == DEFAULT_MODEL
592+ )
569593 assert span .attributes [ErrorAttributes .ERROR_TYPE ] == "ConnectionError"
570594
571595
@@ -586,7 +610,9 @@ def test_responses_create_streaming_user_exception(
586610 raise ValueError ("User raised exception" )
587611
588612 (span ,) = span_exporter .get_finished_spans ()
589- assert span .attributes [GenAIAttributes .GEN_AI_REQUEST_MODEL ] == DEFAULT_MODEL
613+ assert (
614+ span .attributes [GenAIAttributes .GEN_AI_REQUEST_MODEL ] == DEFAULT_MODEL
615+ )
590616 assert span .attributes [ErrorAttributes .ERROR_TYPE ] == "ValueError"
591617
592618
@@ -616,7 +642,9 @@ def exploding_process_event(self, event):
616642 assert len (events ) > 0
617643
618644 (span ,) = span_exporter .get_finished_spans ()
619- assert span .attributes [GenAIAttributes .GEN_AI_REQUEST_MODEL ] == DEFAULT_MODEL
645+ assert (
646+ span .attributes [GenAIAttributes .GEN_AI_REQUEST_MODEL ] == DEFAULT_MODEL
647+ )
620648 assert ErrorAttributes .ERROR_TYPE not in span .attributes
621649
622650
@@ -713,7 +741,11 @@ def test_responses_create_with_content_span_unsampled(
713741
714742@pytest .mark .vcr ()
715743def test_responses_create_with_content_shapes (
716- request , span_exporter , log_exporter , openai_client , instrument_with_content
744+ request ,
745+ span_exporter ,
746+ log_exporter ,
747+ openai_client ,
748+ instrument_with_content ,
717749):
718750 _skip_if_not_latest ()
719751
0 commit comments