From 17f757892cb3a3596166b6aa4aa57633c06d72de Mon Sep 17 00:00:00 2001 From: yucheng-berri <293926326+yucheng-berri@users.noreply.github.com> Date: Tue, 20 Oct 2026 15:44:26 -0700 Subject: [PATCH] test(agentcore): inject the async transport instead of patching the aiohttp flag --- .../agentcore/test_agentcore_transformation.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/unit/llms/bedrock/chat/agentcore/test_agentcore_transformation.py b/tests/unit/llms/bedrock/chat/agentcore/test_agentcore_transformation.py index 8ad70d120ac..b89a56041f9 100644 --- a/tests/unit/llms/bedrock/chat/agentcore/test_agentcore_transformation.py +++ b/tests/unit/llms/bedrock/chat/agentcore/test_agentcore_transformation.py @@ -1299,7 +1299,9 @@ async def _stream_agentcore(body: str, sync_mode: bool) -> list[tuple[str | None ] return [ (chunk.choices[0].delta.content, chunk.choices[0].finish_reason) - async for chunk in await litellm.acompletion(**kwargs, client=AsyncHTTPHandler()) + async for chunk in await litellm.acompletion( + **kwargs, client=AsyncHTTPHandler(transport=httpx.AsyncHTTPTransport()) + ) ] @@ -1310,7 +1312,8 @@ async def _stream_agentcore(body: str, sync_mode: bool) -> list[tuple[str | None pytest.param( 'data: {"event":{"messageStop":{"stopReason":"end_turn"}}}\n\n' 'data: {"event":{"metadata":{"usage":{"inputTokens":9,"outputTokens":7,"totalTokens":16}}}}\n\n' - 'data: {"message":{"role":"assistant","content":[{"text":"Machine learning lets computers learn from data."}]}}\n\n', + 'data: {"message":{"role":"assistant",' + '"content":[{"text":"Machine learning lets computers learn from data."}]}}\n\n', id="strands_full", ), ], @@ -1318,9 +1321,8 @@ async def _stream_agentcore(body: str, sync_mode: bool) -> list[tuple[str | None @pytest.mark.parametrize("sync_mode", [True, False]) @pytest.mark.respx(assert_all_called=True) async def test_agentcore_stream_that_signals_its_end_completes( - ending: str, sync_mode: bool, respx_mock: respx.Router, monkeypatch: pytest.MonkeyPatch + ending: str, sync_mode: bool, respx_mock: respx.Router ) -> None: - monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) respx_mock.post(_AGENTCORE_RUNTIME_URL).mock( return_value=httpx.Response( 200, content=(_AGENTCORE_DELTAS + ending).encode(), headers={"content-type": "text/event-stream"} @@ -1335,10 +1337,7 @@ async def test_agentcore_stream_that_signals_its_end_completes( @pytest.mark.parametrize("sync_mode", [True, False]) @pytest.mark.respx(assert_all_called=True) -async def test_agentcore_stream_cut_before_it_signals_its_end_raises( - sync_mode: bool, respx_mock: respx.Router, monkeypatch: pytest.MonkeyPatch -) -> None: - monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) +async def test_agentcore_stream_cut_before_it_signals_its_end_raises(sync_mode: bool, respx_mock: respx.Router) -> None: respx_mock.post(_AGENTCORE_RUNTIME_URL).mock( return_value=httpx.Response( 200, content=_AGENTCORE_DELTAS.encode(), headers={"content-type": "text/event-stream"}