From ab658d7d500561d820cacd509a43f2ff640d19d3 Mon Sep 17 00:00:00 2001 From: Julio Quinteros Pro Date: Mon, 26 Jan 2026 02:46:23 -0300 Subject: [PATCH] Fix pillar guardrails tests for parallel execution The setup_and_teardown fixture was failing with "ImportError: module litellm not in sys.modules" during parallel test execution. This occurs because another worker might have removed/modified litellm from sys.modules before this test tries to reload it. Fix: Check if litellm is in sys.modules before attempting reload. --- .../proxy/guardrails/test_pillar_guardrails.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_litellm/proxy/guardrails/test_pillar_guardrails.py b/tests/test_litellm/proxy/guardrails/test_pillar_guardrails.py index 0607b0de98..392a047b5c 100644 --- a/tests/test_litellm/proxy/guardrails/test_pillar_guardrails.py +++ b/tests/test_litellm/proxy/guardrails/test_pillar_guardrails.py @@ -51,9 +51,15 @@ def setup_and_teardown(): """ import importlib import asyncio + import sys # Reload litellm to ensure clean state - importlib.reload(litellm) + # During parallel test execution, another worker might have removed litellm from sys.modules + # so we need to ensure it's imported before reloading + if "litellm" not in sys.modules: + import litellm as _litellm + else: + importlib.reload(litellm) # Set up async loop loop = asyncio.get_event_loop_policy().new_event_loop()