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.
This commit is contained in:
Julio Quinteros Pro
2026-02-15 13:08:41 -03:00
parent 7dcef86cc6
commit ab658d7d50
@@ -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()