From 47ebc964eb8e3ed266a3d7a5473299050d262a36 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Thu, 30 Jul 2026 20:55:32 -0700 Subject: [PATCH] test: patch unified guardrail mapping global instead of loader to fix order-dependent flake --- .../test_passthrough_post_call_guardrails.py | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/test_litellm/proxy/pass_through_endpoints/test_passthrough_post_call_guardrails.py b/tests/test_litellm/proxy/pass_through_endpoints/test_passthrough_post_call_guardrails.py index a2f7476abd1..470179a0429 100644 --- a/tests/test_litellm/proxy/pass_through_endpoints/test_passthrough_post_call_guardrails.py +++ b/tests/test_litellm/proxy/pass_through_endpoints/test_passthrough_post_call_guardrails.py @@ -294,19 +294,22 @@ class TestUnifiedGuardrailCallTypeResolution: response_body = {"candidates": [{"content": {"parts": [{"text": "hello"}]}}]} - with patch( - "litellm.proxy.guardrails.guardrail_hooks.unified_guardrail.unified_guardrail.load_guardrail_translation_mappings" - ) as mock_load: - mock_handler_instance = AsyncMock() - mock_handler_instance.process_output_response = AsyncMock( - return_value=response_body - ) - mock_handler_class = MagicMock(return_value=mock_handler_instance) + mock_handler_instance = AsyncMock() + mock_handler_instance.process_output_response = AsyncMock( + return_value=response_body + ) + mock_handler_class = MagicMock(return_value=mock_handler_instance) - from litellm.types.utils import CallTypes - - mock_load.return_value = {CallTypes.pass_through: mock_handler_class} + from litellm.proxy.guardrails.guardrail_hooks.unified_guardrail import ( + unified_guardrail as unified_guardrail_module, + ) + from litellm.types.utils import CallTypes + with patch.object( + unified_guardrail_module, + "endpoint_guardrail_translation_mappings", + {CallTypes.pass_through: mock_handler_class}, + ): result = await unified.async_post_call_success_hook( data=data, user_api_key_dict=user_api_key_dict,