Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Fix test isolation: save/restore pre_call_rules and post_call_rules

yuneng-jiang968d7a3eca3b
diff --git a/tests/local_testing/conftest.py b/tests/local_testing/conftest.py
index 6c5c0d3b35c..71cfec4157b 100644
--- a/tests/local_testing/conftest.py
+++ b/tests/local_testing/conftest.py
@@ -43,6 +43,12 @@ def isolate_litellm_state():
if hasattr(litellm, attr):
original_state[attr] = getattr(litellm, attr)
+ # Save rules that tests may set (e.g. test_rules.py)
+ for attr in ("pre_call_rules", "post_call_rules"):
+ if hasattr(litellm, attr):
+ val = getattr(litellm, attr)
+ original_state[attr] = val.copy() if val else []
+
# Save transport/network globals
for attr in ("disable_aiohttp_transport", "force_ipv4"):
if hasattr(litellm, attr):
@@ -52,13 +58,15 @@ def isolate_litellm_state():
if hasattr(litellm, "in_memory_llm_clients_cache"):
litellm.in_memory_llm_clients_cache.flush_cache()
- # Clear callbacks before test
+ # Clear callbacks and rules before test
for attr in (
"callbacks",
"success_callback",
"failure_callback",
"_async_success_callback",
"_async_failure_callback",
+ "pre_call_rules",
+ "post_call_rules",
):
if hasattr(litellm, attr):
setattr(litellm, attr, [])