fix: address Greptile review feedback for test isolation

- test_pillar_guardrails.py: Fix fixture to properly update module-level
  litellm reference using global keyword and assignment from reload
- test_anthropic_experimental_pass_through_messages_handler.py: Add missing
  assert keywords to kwargs comparison statements (lines 36, 60-62)
- test_proxy_server.py: Replace silent pytest.skip with explicit assertion
  to catch router initialization regressions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Julio Quinteros Pro
2026-02-17 21:28:23 -03:00
co-authored by Claude Opus 4.5
parent ab6d2eefb9
commit 77f315eb11
3 changed files with 14 additions and 10 deletions
@@ -33,7 +33,7 @@ def test_anthropic_experimental_pass_through_messages_handler():
except Exception as e:
print(f"Error: {e}")
mock_completion.assert_called_once()
mock_completion.call_args.kwargs["api_key"] == "test-api-key"
assert mock_completion.call_args.kwargs["api_key"] == "test-api-key"
def test_anthropic_experimental_pass_through_messages_handler_dynamic_api_key_and_api_base_and_custom_values():
@@ -57,9 +57,9 @@ def test_anthropic_experimental_pass_through_messages_handler_dynamic_api_key_an
except Exception as e:
print(f"Error: {e}")
mock_completion.assert_called_once()
mock_completion.call_args.kwargs["api_key"] == "test-api-key"
mock_completion.call_args.kwargs["api_base"] == "test-api-base"
mock_completion.call_args.kwargs["custom_key"] == "custom_value"
assert mock_completion.call_args.kwargs["api_key"] == "test-api-key"
assert mock_completion.call_args.kwargs["api_base"] == "test-api-base"
assert mock_completion.call_args.kwargs["custom_key"] == "custom_value"
def test_anthropic_experimental_pass_through_messages_handler_custom_llm_provider():
@@ -51,14 +51,16 @@ def setup_and_teardown():
import asyncio
import importlib
import sys
global litellm
# Reload litellm to ensure clean state
# 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
import litellm as fresh_litellm
litellm = fresh_litellm # Update module-level reference
else:
importlib.reload(litellm)
litellm = importlib.reload(litellm) # Update module-level reference with reloaded module
# Set up async loop
loop = asyncio.get_event_loop_policy().new_event_loop()
@@ -681,10 +681,12 @@ def test_embedding_input_array_of_tokens(client_no_auth):
"""
from litellm.proxy import proxy_server
# Apply the mock AFTER client_no_auth fixture has initialized the router
# This avoids issues with llm_router being None during parallel test execution
if proxy_server.llm_router is None:
pytest.skip("llm_router not initialized - skipping test")
# The client_no_auth fixture should initialize the router
# Assert this to catch any router initialization regressions
assert proxy_server.llm_router is not None, (
"llm_router is None after client_no_auth fixture initialized. "
"This indicates a router initialization issue that should be investigated."
)
try:
with mock.patch.object(