Commit graph

6280 commits

Author SHA1 Message Date
Julio Quinteros Pro
392fa61ac3 fix(test): flush client cache before test_extra_body_with_fallback
Add client cache flush before setting disable_aiohttp_transport to prevent
cache pollution. Previous tests may cache HTTP clients with aiohttp enabled,
which bypass respx mocks and cause real API calls to fail.

This follows the same pattern as test_openai_env_base which also uses respx.

Related to #8425

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 14:18:00 -03:00
Julio Quinteros Pro
4c53ccd90d refactor: remove dead code from Langfuse test cleanup
Follow-up to PR #21248 addressing greptile code review feedback.

Removes hasattr checks for non-existent attributes that were identified
as dead code by greptile automated code review.

Changes:
- Remove hasattr check for LangFuseLogger._langfuse_clients (class attribute doesn't exist)
- Remove hasattr check for self.logger._langfuse_client_cache (instance attribute doesn't exist)
- Update comments to be more accurate about what cleanup is being done

The core fix from PR #21248 (nulling Langfuse reference and deleting
logger instance) remains unchanged and effective. This just removes
misleading dead code that serves no purpose.

Context:
These checks were added defensively but reference attributes that don't
actually exist on the LangFuseLogger class, making them always no-ops.
Greptile correctly identified these as dead code in PR #21248 review,
but the PR was merged before the cleanup could be applied.

Related: #21248

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 13:45:23 -03:00
jquinter
c362804872
Merge pull request #21250 from BerriAI/fix/test-extra-body-fallback-isolation
fix(test): add cleanup for disable_aiohttp_transport in test_extra_body_with_fallback
2026-02-15 13:41:57 -03:00
jquinter
9a590ce969
Merge pull request #21251 from BerriAI/fix/video-test-http-client-isolation
fix(test): add mock isolation for test_video_content_handler_uses_get_for_openai
2026-02-15 13:41:19 -03:00
jquinter
a4deaaa7ac
Update tests/test_litellm/test_main.py
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-02-15 13:34:32 -03:00
Julio Quinteros Pro
6691694759 fix(test): add mock isolation for test_video_content_handler_uses_get_for_openai
Fixes test isolation issue where test_video_content_handler_uses_get_for_openai
was making real HTTP requests to OpenAI API instead of using the mock client.

Changes:
- Patch _get_httpx_client to ensure it returns the mock client
- Prevents creation of real HTTP client even if isinstance check fails
- Wraps handler call in context manager for proper cleanup

Root Cause:
When run after other tests, the isinstance(mock_client, HTTPHandler) check
in video_content_handler() could fail due to state pollution, causing the
handler to create a real HTTP client via _get_httpx_client(). This resulted in:
- Real API calls to https://api.openai.com/v1/videos/video_abc/content
- 401 errors: "Incorrect API key provided: sk-test"
- Test expecting b'mp4-bytes' but getting actual error response

Impact:
Test passes in isolation but fails when run with other tests, especially
in CI environments with parallel execution.

Fixes: Test isolation for test_video_content_handler_uses_get_for_openai

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 13:34:19 -03:00
Julio Quinteros Pro
a2a3d14443 fix(test): add cleanup for disable_aiohttp_transport in test_extra_body_with_fallback
Fixes test isolation issue where test_extra_body_with_fallback was setting
litellm.disable_aiohttp_transport = True but never resetting it, causing
state pollution that affected other tests.

Changes:
- Save original value of disable_aiohttp_transport before modifying
- Wrap test logic in try/finally block
- Restore original value in finally to ensure cleanup even on failure

Root Cause:
The test was modifying global litellm state without cleanup. When run in
certain orders with other tests:
- If this test ran first, it left disable_aiohttp_transport=True globally
- If other tests ran first, their state could interfere with this test
- Result: "All fallback attempts failed" error in CI

Impact:
Test passes in isolation but fails when run with other tests, especially
in parallel execution or CI environments.

Fixes: Test isolation for test_extra_body_with_fallback

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 13:31:30 -03:00
Julio Quinteros Pro
c4fa7e9298 fix(test): improve Langfuse test isolation to prevent flaky failures
Enhances test isolation in TestLangfuseUsageDetails by ensuring the
logger instance is completely fresh for each test and properly cleaned
up afterward.

Changes:
- Clear any class-level cached Langfuse clients before creating logger
- Reset logger's cached client instances in setUp
- Properly clean up logger instance and its state in tearDown

Root Cause:
The test_log_langfuse_v2_handles_null_usage_values test was failing
when run after other tests due to lingering state in the logger instance.
While the test passes in isolation, test ordering issues caused it to
fail with "Expected 'generation' to have been called once. Called 0 times."

This builds on PR #21214 which added sys.modules cleanup, but that wasn't
sufficient to prevent all state leakage between tests.

Fixes: Test isolation issues in test_log_langfuse_v2_handles_null_usage_values

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 13:28:12 -03:00
jquinter
068c994d89
Merge pull request #21075 from jquinter/fix/policy-endpoints-import-error
fix: make policy_resolve_endpoints importable without FastAPI
2026-02-15 13:18:21 -03:00
jquinter
f555846c83
Merge pull request #21227 from BerriAI/fix/sso-test-premium-check
Fix SSO test flakiness by correctly mocking premium_user
2026-02-15 13:18:08 -03:00
Julio Quinteros Pro
bee4c94556 Fix Vertex AI rerank tests for parallel test execution
The test_end_to_end_rerank_flow mock for _ensure_access_token was not
being applied because conftest reloads litellm, causing the
VertexAIRerankConfig class to be a different object than what's patched.

Fix: Reload the transformation module in setup_method and re-import the
class to ensure the patch targets the same class object used by tests.
2026-02-15 13:08:47 -03:00
Julio Quinteros Pro
8285a2a7b4 Fix HuggingFace embedding tests for parallel test execution
The tests were making real API calls instead of using mocks because
conftest.py reloads litellm at module scope, causing the HTTPHandler
class reference in the HuggingFace embedding handler to become stale.
The patches were applied to the new class, but the handler used the old one.

Fix: Add a reload_huggingface_modules fixture that reloads the relevant
modules BEFORE the mock fixtures apply their patches. This ensures all
references point to the same class object.
2026-02-15 13:08:47 -03:00
Julio Quinteros Pro
59d3c75462 Fix test_error_handling_integration for parallel test execution
The test was making real API calls instead of using mocks because the
conftest.py reloads litellm at module scope, causing stale module
references. The mock was patching the old reference while the actual
code used the new one.

Fix: Reload litellm.containers.main inside the test to get a fresh
reference to base_llm_http_handler, then re-import create_container
after the reload.
2026-02-15 13:08:47 -03:00
Julio Quinteros Pro
ab658d7d50 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.
2026-02-15 13:08:41 -03:00
Julio Quinteros Pro
7dcef86cc6 Fix test_embedding_header_forwarding_with_model_group for parallel test execution
- Reload litellm_pre_call_utils module inside test to get fresh litellm reference
- Use string-based patch("litellm.model_group_settings") instead of patch.object
- These changes ensure the patch targets the correct module after conftest reloads litellm
2026-02-15 13:08:41 -03:00
Julio Quinteros Pro
c52251ca72 test: Fix test isolation issues caused by module reloading
Fix several tests that fail in CI due to parallel test execution and
module reloading in conftest.py.

1. test_empty_assistant_message_handling:
   - Use patch.object on factory_module.litellm instead of direct assignment
   - Ensures the correct litellm reference is modified after conftest reloads

2. test_embedding_header_forwarding_with_model_group:
   - Use patch.object on pre_call_utils_module.litellm instead of direct assignment
   - Same fix for module reloading issue

3. test_embedding_input_array_of_tokens:
   - Move mock inside test function (after fixture initializes router)
   - Add skip condition if llm_router is None
   - Fixes "AttributeError: None does not have 'aembedding'" in parallel execution

Root cause: conftest.py reloads litellm at module scope, which can cause:
- Different litellm references between test code and library code
- Global state (like llm_router) being None at decorator execution time
- isinstance checks failing due to class identity mismatches
2026-02-15 13:08:41 -03:00
Julio Quinteros Pro
97f4cfc14a test: Fix additional broken tests
1. test_bedrock_converse_budget_tokens_preserved:
   - Fixed mocking at the correct level (litellm.acompletion instead of client.post)
   - The previous mock didn't work because the code runs through run_in_executor
     and the passed client parameter was not being used

2. test_error_class_returns_volcengine_error:
   - Changed isinstance check to class name comparison
   - This avoids issues when module reloading (in conftest.py) causes class
     identity mismatches during parallel test execution
2026-02-15 13:08:41 -03:00
Julio Quinteros Pro
8d15996b5a test: Fix flaky tests with proper mocking and skip conditions
1. test_acompletion_with_mcp_streaming_metadata_in_correct_chunks:
   - Moved stream consumption inside patch context to avoid real API calls
   - The previous implementation had assertions outside the `with patch(...)`
     block, causing real OpenAI API calls when consuming the stream

2. TestCheckResponsesCost tests:
   - Added skip condition when litellm_enterprise module is not available
   - These tests import from litellm_enterprise.proxy.common_utils.check_responses_cost
     which is only available in the enterprise version
2026-02-15 13:08:30 -03:00
Julio Quinteros Pro
12fddb4b8a Fix SSO test flakiness by mocking premium_user correctly
The test_sso_key_generate_shows_deprecation_banner test was failing in CI
with a 403 Forbidden error because the SSO endpoint checks for premium_user
at line 297 in ui_sso.py.

The fix adds a monkeypatch for premium_user at its source location
(litellm.proxy.proxy_server.premium_user) to bypass the enterprise check
during testing.

Fixes the intermittent test failure where the endpoint would return 403
instead of the expected 200 status code.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 13:05:37 -03:00
jquinter
a7b4c7536f
Merge pull request #21216 from BerriAI/fix/anthropic-bedrock-test-flakiness
fix(test): resolve merge conflict and fix bedrock thinking test flakiness
2026-02-15 12:45:15 -03:00
Julio Quinteros Pro
54c24a8d08 fix(test): resolve merge conflict and fix bedrock thinking test flakiness
This commit addresses two issues:

1. **Merge conflict resolution**: Resolved merge conflict in litellm/integrations/opentelemetry.py
   that was preventing imports from working. The conflict was in the OpenTelemetry SDK
   LogRecord import section.

2. **Test flakiness fix**: Fixed intermittent failures in test_bedrock_converse_budget_tokens_preserved
   by properly configuring mock objects to avoid unawaited coroutine warnings.

The test was failing in CI with "Expected 'post' to have been called once. Called 0 times."
The root cause was improper mock setup where AsyncMock was creating async child methods
(raise_for_status, json) that returned unawaited coroutines, causing unreliable behavior
across different Python versions and test environments.

**Changes:**
- Set raise_for_status() and json() as explicit MagicMock instances on the response
- Use AsyncMock explicitly for the post() method via patch.object's 'new' parameter
- This ensures response methods are synchronous while the HTTP call remains async

**Testing:**
- Test now passes consistently across 5 consecutive runs
- RuntimeWarnings about unawaited coroutines eliminated (18 warnings → 16 warnings)
- Request JSON verification shows budget_tokens correctly preserved

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 12:31:26 -03:00
Julio Quinteros Pro
76e1b2c015 Remove redundant sys.modules cleanup in Langfuse test tearDown
The manual sys.modules restoration code was redundant because
patch.dict.stop() automatically handles the cleanup. This simplifies
the tearDown method and removes the now-unused _original_langfuse_module
instance variable.

Addresses review comment: https://github.com/BerriAI/litellm/pull/21214#pullrequestreview-3802348462

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 12:26:02 -03:00
Julio Quinteros Pro
9672a1f015 Fix Langfuse test isolation to prevent flaky failures
Fixes test_log_langfuse_v2_handles_null_usage_values flaky test failure
by properly cleaning up sys.modules['langfuse'] in tearDown.

Changes:
- Store original langfuse module in setUp before mocking
- Restore original or remove mock in tearDown to prevent state pollution
- Remove invalid print_verbose parameter from log_event_on_langfuse

Root Cause:
The tearDown method was not cleaning up sys.modules['langfuse'] after
each test, causing mock state to leak between tests. This caused
intermittent failures in CI, especially when tests run in parallel or
in different orders.

Impact:
This test has a long history of flakiness with multiple attempted fixes
(#20475, #17599, #17594, #17591, #17588). The missing sys.modules cleanup
was the underlying issue causing continued failures despite those patches.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 12:26:02 -03:00
Shivam Rawat
db9b98caf3
Merge branch 'main' into litellm_preserver_team_key_alias_after_key_regeneration_and_deletion 2026-02-14 16:59:52 -08:00
yuneng-jiang
55f169aa69
Merge pull request #21190 from BerriAI/litellm_access_groups_inte
[Feature] Access Group Checks
2026-02-14 16:28:09 -08:00
Ishaan Jaffer
9ce7871d8a test_queue_flush_limit 2026-02-14 15:34:45 -08:00
Ishaan Jaffer
703bf5add0 BUMP Enterprise PIP 2026-02-14 13:40:48 -08:00
yuneng-jiang
5cf91e573e Merge remote-tracking branch 'origin' into litellm_access_groups_inte 2026-02-14 13:27:36 -08:00
Ishaan Jaffer
55a78e564d test_anthropic_messages_with_all_beta_headers 2026-02-14 13:03:52 -08:00
Ishaan Jaffer
add3183308 IGNORE_FUNCTIONS 2026-02-14 12:59:15 -08:00
Ishaan Jaffer
b8f572fc39 test_responses_api_shell_tool_streaming_sees_shell_output 2026-02-14 12:55:44 -08:00
Ishaan Jaffer
3987198fca test_partner_models_httpx_streaming 2026-02-14 12:41:35 -08:00
Ishaan Jaffer
6a4b531057 def get_advanced_model_for_shell_tool(self) -> Optional[str]:
AZURE
2026-02-14 12:29:42 -08:00
Ishaan Jaffer
bab2bcad8c test_openai_codex_stream 2026-02-14 12:28:18 -08:00
Ishaan Jaffer
582fbf9040 test_anthropic_custom_headers 2026-02-14 12:22:14 -08:00
Ishaan Jaffer
ec7eb79634 ANTHROPIC_API_KEY 2026-02-14 12:20:55 -08:00
Ishaan Jaffer
ad72d162cd avector_store_create 2026-02-14 12:16:33 -08:00
Krish Dholakia
fa0b26c611
ci/cd fixes (#21218)
* fix: add a2a-sdk to dev deps

* fix: fix test

* fix: update poetry lock

* test: cleanup bad/hanging tests
2026-02-14 12:11:53 -08:00
Ishaan Jaffer
e373da6653 test_partner_models_httpx_streaming 2026-02-14 12:09:18 -08:00
Alexsander Hamir
7944b67842
Fix CI/CD pyroscope test failure (#21219) 2026-02-14 12:07:20 -08:00
Ishaan Jaffer
e5bbafba62 test_completion_openrouter_reasoning_effort 2026-02-14 12:04:05 -08:00
Ishaan Jaffer
ff9fbe7fe2 test_other_constraints_preserved 2026-02-14 12:00:48 -08:00
Ishaan Jaffer
77dd3cb2b2 test_responses_api_shell_tool_streaming_sees_shell_output 2026-02-14 11:32:52 -08:00
Ishaan Jaffer
1730008657 claude-sonnet-4-5-20250929 2026-02-14 11:28:45 -08:00
mubashir1osmani
4727aa41fc
fix(langfuse_otel): prevent empty proxy request spans from being sent to Langfuse
fix(langfuse_otel): prevent empty proxy request spans from being sent to Langfuse
2026-02-14 14:22:32 -05:00
Ishaan Jaffer
ad910de1e3 test_o1_parallel_tool_calls 2026-02-14 10:47:38 -08:00
Ishaan Jaffer
8d9ae1d2b4 codex test fixes 2026-02-14 09:56:45 -08:00
Krish Dholakia
e41ecc7a71
Guardrails - add nsfw policy template, toxic keywords in multiple languages, child safety content filter, json content viewer (#21205)
* fix(content_filter.py): fix filter on toxic keywords

* feat: improve toxic/abusive language detection

* fix: additional improvements to nsfw filters

* feat: more improvements to nsfw filter

* feat(content_filter.json): add new australia specific nsfw content filter

ensure complete coverage for australia nsfw

* fix: cleanup policy templates

* fix(index.tsx): alert notice

* fix(index.tsx): add disclaimer notice

* feat(harmful_child_safety.yaml): new child safety content filter

ensure we catch inappropriate, child-specific content

* feat(policy_templates.json): add child safety and self harm filters

* fix(content_filter.py): improve racial bias filter to use a similar identifier + block word pattern and cover a wider range of ethnicities

* feat(policy_templates.json): add racial bias to nsfw policy template

* feat: add json content viewer
2026-02-14 09:41:55 -08:00
yuneng-jiang
c311033f48 cache adjustment for deleted teams and keys 2026-02-14 09:28:02 -08:00
Ishaan Jaff
f8334dfeda
ci/cd fixes - streaming role & bedrock model cost (#21200)
* fix(model_cost): add missing supports_system_messages and supports_tool_choice to bedrock/moonshotai.kimi-k2.5

* fix(streaming): ensure role=assistant is set on first streaming chunk via strip_role_from_delta

* fix(vertex_ai): ensure role=assistant on first streaming chunk for Llama models

Add VertexAILlama3StreamingHandler that injects role='assistant' into the
first streaming chunk delta when the Vertex AI Llama API omits it.
2026-02-14 09:18:29 -08:00