From de758402dfdf8f8f962970e0be165906717b6586 Mon Sep 17 00:00:00 2001 From: Neel Shah Date: Tue, 26 May 2026 15:33:18 +0200 Subject: [PATCH] ci(openai_agents): fix asyncio loop missing for sync tests --- .../openai_agents/test_openai_agents.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/integrations/openai_agents/test_openai_agents.py b/tests/integrations/openai_agents/test_openai_agents.py index 2cc33d6fd7..cfe23f922a 100644 --- a/tests/integrations/openai_agents/test_openai_agents.py +++ b/tests/integrations/openai_agents/test_openai_agents.py @@ -49,6 +49,21 @@ test_run_config = agents.RunConfig(tracing_disabled=True) + +@pytest.fixture +def sync_event_loop(): + # agents.Runner.run_sync() in openai-agents v0.0.19 calls + # asyncio.get_event_loop(), which on Python 3.12+ no longer auto-creates + # a loop when none is set on the thread. + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + try: + yield loop + finally: + loop.close() + asyncio.set_event_loop(None) + + EXAMPLE_RESPONSE = Response( id="chat-id", output=[ @@ -952,6 +967,7 @@ def test_agent_invocation_span_sync_no_pii( nonstreaming_responses_model_response, get_model_response, stream_gen_ai_spans, + sync_event_loop, ): """ Test that the integration creates spans for agent invocations. @@ -1181,6 +1197,7 @@ def test_agent_invocation_span_sync( request, get_model_response, stream_gen_ai_spans, + sync_event_loop, ): """ Test that the integration creates spans for agent invocations.