From be63bac1c11f6cda4ef1fb66ff99929d98dc7c69 Mon Sep 17 00:00:00 2001 From: Julio Quinteros Pro Date: Sun, 15 Feb 2026 19:39:21 -0300 Subject: [PATCH] fix(test): use async side_effect for client.post mock in watsonx test The test_watsonx_gpt_oss_prompt_transformation was using return_value to mock an async method (AsyncHTTPHandler.post), which doesn't work correctly with async/await. This could cause intermittent failures in CI due to test ordering. Changed to use side_effect with an async function (mock_post_func) to properly mock the async post method, following the same pattern used in other async tests like test_vertex_ai_gpt_oss_reasoning_effort. This ensures the mock is always called correctly regardless of test execution order or parallel test execution. Co-Authored-By: Claude Sonnet 4.5 --- tests/test_litellm/llms/watsonx/test_watsonx.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/test_litellm/llms/watsonx/test_watsonx.py b/tests/test_litellm/llms/watsonx/test_watsonx.py index f325af6b36..1b09872a8a 100644 --- a/tests/test_litellm/llms/watsonx/test_watsonx.py +++ b/tests/test_litellm/llms/watsonx/test_watsonx.py @@ -289,15 +289,19 @@ async def test_watsonx_gpt_oss_prompt_transformation(monkeypatch): # template is always used regardless of test execution order. hf_model = "openai/gpt-oss-120b" litellm.known_tokenizer_config[hf_model] = mock_tokenizer_config - + # Also create sync mock functions in case the fallback sync path is used def mock_get_tokenizer_config(hf_model_name: str): return mock_tokenizer_config def mock_get_chat_template_file(hf_model_name: str): return {"status": "failure"} - - with patch.object(client, "post") as mock_post, patch.object( + + # Async mock function for client.post to properly handle async method mocking + async def mock_post_func(*args, **kwargs): + return mock_completion_response + + with patch.object(client, "post", side_effect=mock_post_func) as mock_post, patch.object( litellm.module_level_client, "post", return_value=mock_token_response ), patch( "litellm.litellm_core_utils.prompt_templates.huggingface_template_handler._aget_tokenizer_config", @@ -312,9 +316,6 @@ async def test_watsonx_gpt_oss_prompt_transformation(monkeypatch): "litellm.litellm_core_utils.prompt_templates.huggingface_template_handler._get_chat_template_file", side_effect=mock_get_chat_template_file, ): - # Set the mock to return the completion response - mock_post.return_value = mock_completion_response - try: # Call acompletion with messages await litellm.acompletion(