From a673484e21de40626cad334bd251d394f7bec3af Mon Sep 17 00:00:00 2001 From: Matthew Farrellee Date: Fri, 12 Sep 2025 13:13:13 -0400 Subject: [PATCH] make sure the mock method identifies as a coroutine --- .../unit/distribution/test_inference_recordings.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/unit/distribution/test_inference_recordings.py b/tests/unit/distribution/test_inference_recordings.py index f1d606fc2..d9cda5af9 100644 --- a/tests/unit/distribution/test_inference_recordings.py +++ b/tests/unit/distribution/test_inference_recordings.py @@ -6,7 +6,7 @@ import tempfile from pathlib import Path -from unittest.mock import Mock, patch +from unittest.mock import AsyncMock, Mock, patch import pytest from openai import AsyncOpenAI @@ -159,7 +159,9 @@ class TestInferenceRecording: return real_openai_chat_response temp_storage_dir = temp_storage_dir / "test_recording_mode" - with patch("openai.resources.chat.completions.AsyncCompletions.create", side_effect=mock_create): + with patch( + "openai.resources.chat.completions.AsyncCompletions.create", new_callable=AsyncMock, side_effect=mock_create + ): with inference_recording(mode=InferenceMode.RECORD, storage_dir=str(temp_storage_dir)): client = AsyncOpenAI(base_url="http://localhost:11434/v1", api_key="test") @@ -185,7 +187,9 @@ class TestInferenceRecording: temp_storage_dir = temp_storage_dir / "test_replay_mode" # First, record a response - with patch("openai.resources.chat.completions.AsyncCompletions.create", side_effect=mock_create): + with patch( + "openai.resources.chat.completions.AsyncCompletions.create", new_callable=AsyncMock, side_effect=mock_create + ): with inference_recording(mode=InferenceMode.RECORD, storage_dir=str(temp_storage_dir)): client = AsyncOpenAI(base_url="http://localhost:11434/v1", api_key="test") @@ -277,7 +281,9 @@ class TestInferenceRecording: temp_storage_dir = temp_storage_dir / "test_embeddings_recording" # Record - with patch("openai.resources.embeddings.AsyncEmbeddings.create", side_effect=mock_create): + with patch( + "openai.resources.embeddings.AsyncEmbeddings.create", new_callable=AsyncMock, side_effect=mock_create + ): with inference_recording(mode=InferenceMode.RECORD, storage_dir=str(temp_storage_dir)): client = AsyncOpenAI(base_url="http://localhost:11434/v1", api_key="test")