Skip to content

Commit d204945

Browse files
test(openai-agents): Remove test for unreachable state (#5584)
The OpenAI API always returns the response model for both Completions and Responses APIs. The test previously mocked a Responses object without a response model, which cannot occur when using the Responses API with `openai-agents`.
1 parent 2ae0c03 commit d204945

File tree

1 file changed

+0
-69
lines changed

1 file changed

+0
-69
lines changed

tests/integrations/openai_agents/test_openai_agents.py

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,75 +2513,6 @@ def calculator(a: int, b: int) -> int:
25132513
assert invoke_agent_span["data"]["gen_ai.usage.output_tokens.reasoning"] == 3
25142514

25152515

2516-
@pytest.mark.asyncio
2517-
async def test_response_model_not_set_when_unavailable(
2518-
sentry_init, capture_events, test_agent
2519-
):
2520-
"""
2521-
Test that response model is not set if the API response doesn't have a model field.
2522-
The request model should still be set correctly.
2523-
"""
2524-
2525-
with patch.dict(os.environ, {"OPENAI_API_KEY": "test-key"}):
2526-
with patch(
2527-
"agents.models.openai_responses.OpenAIResponsesModel._fetch_response"
2528-
) as mock_fetch_response:
2529-
# Create a mock response without a model field
2530-
mock_response = MagicMock()
2531-
mock_response.model = None # No model in response
2532-
mock_response.id = "resp_123"
2533-
mock_response.output = [
2534-
ResponseOutputMessage(
2535-
id="msg_123",
2536-
type="message",
2537-
status="completed",
2538-
content=[
2539-
ResponseOutputText(
2540-
text="Response without model field",
2541-
type="output_text",
2542-
annotations=[],
2543-
)
2544-
],
2545-
role="assistant",
2546-
)
2547-
]
2548-
mock_response.usage = MagicMock()
2549-
mock_response.usage.input_tokens = 10
2550-
mock_response.usage.output_tokens = 20
2551-
mock_response.usage.total_tokens = 30
2552-
mock_response.usage.input_tokens_details = InputTokensDetails(
2553-
cached_tokens=0
2554-
)
2555-
mock_response.usage.output_tokens_details = OutputTokensDetails(
2556-
reasoning_tokens=0
2557-
)
2558-
2559-
mock_fetch_response.return_value = mock_response
2560-
2561-
sentry_init(
2562-
integrations=[OpenAIAgentsIntegration()],
2563-
traces_sample_rate=1.0,
2564-
)
2565-
2566-
events = capture_events()
2567-
2568-
result = await agents.Runner.run(
2569-
test_agent, "Test input", run_config=test_run_config
2570-
)
2571-
2572-
assert result is not None
2573-
2574-
(transaction,) = events
2575-
spans = transaction["spans"]
2576-
_, ai_client_span = spans
2577-
2578-
# Response model should NOT be set when API doesn't return it
2579-
assert "gen_ai.response.model" not in ai_client_span["data"]
2580-
# But request model should still be set
2581-
assert "gen_ai.request.model" in ai_client_span["data"]
2582-
assert ai_client_span["data"]["gen_ai.request.model"] == "gpt-4"
2583-
2584-
25852516
@pytest.mark.asyncio
25862517
async def test_invoke_agent_span_includes_response_model(
25872518
sentry_init, capture_events, test_agent

0 commit comments

Comments
 (0)