From db16d964c9437a58b4b6cad1f6b8c70499c6e6d3 Mon Sep 17 00:00:00 2001 From: Charan Rathore Date: Mon, 28 Sep 2026 09:42:31 +0530 Subject: [PATCH] test: capture audio handle through mock call --- .../unit/litellm_core_utils/test_health_check_helpers.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/unit/litellm_core_utils/test_health_check_helpers.py b/tests/unit/litellm_core_utils/test_health_check_helpers.py index 8870a5bd9f7..6e7e54c60e6 100644 --- a/tests/unit/litellm_core_utils/test_health_check_helpers.py +++ b/tests/unit/litellm_core_utils/test_health_check_helpers.py @@ -40,11 +40,8 @@ def _distinct_rgb_colors(png: bytes) -> set[bytes]: @pytest.mark.asyncio @pytest.mark.parametrize("raises", [False, True]) async def test_audio_transcription_health_check_closes_file(raises: bool): - file_handles = [] - async def transcription(**kwargs): file = kwargs["file"] - file_handles.append(file) assert not file.closed assert file.read(4) == b"RIFF" if raises: @@ -56,15 +53,15 @@ async def test_audio_transcription_health_check_closes_file(raises: bool): custom_llm_provider="openai", model_params={"model": "openai/whisper-1", "api_key": "sk-test"}, ) - with patch("litellm.atranscription", side_effect=transcription): + with patch("litellm.atranscription", side_effect=transcription) as mock_transcription: if raises: with pytest.raises(RuntimeError, match="transcription failed"): await handlers["audio_transcription"]() else: assert await handlers["audio_transcription"]() == {"text": "healthy"} - assert len(file_handles) == 1 - assert file_handles[0].closed + mock_transcription.assert_called_once() + assert mock_transcription.call_args.kwargs["file"].closed @pytest.mark.asyncio