Commit Graph
8 Commits
Author SHA1 Message Date
Julio Quinteros ProandClaude Opus 4.5 ab6d2eefb9 fix: improve test isolation for parallel execution
Fixes test failures that occur during parallel test execution (pytest -n 4)
due to module reloading issues with conftest.py reloading litellm.

Changes:
- Add module reload fixtures to ensure fresh references after conftest reloads
- Use patch.object and string-based patches instead of direct attribute assignment
- Use class name comparison instead of isinstance for reloaded modules
- Handle case where litellm is missing from sys.modules during parallel runs
- Move stream consumption inside patch contexts to avoid real API calls
- Mock litellm.acompletion instead of low-level HTTP handlers
- Add skipif decorator for enterprise-only test classes

Affected test files:
- test_container_integration.py
- test_responses_background_cost.py
- test_huggingface_embedding_handler.py
- test_vertex_ai_rerank_integration.py
- test_volcengine_responses_transformation.py
- test_pillar_guardrails.py
- test_litellm_pre_call_utils.py
- test_proxy_server.py
- test_converse_transformation.py
- test_chat_completions_handler.py
- test_aresponses_api_with_mcp.py
- test_anthropic_experimental_pass_through_messages_handler.py

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-17 21:28:23 -03:00
Julio Quinteros ProandClaude Sonnet 4.6 a6df01caec fix: remove importlib.reload calls that cause cross-test class-reference staleness
Two test files were reloading modules in setup_method/fixtures, which
caused class-reference staleness for subsequent tests in the same worker:

1. test_huggingface_embedding_handler.py reloaded
   litellm.llms.custom_httpx.http_handler, creating a new HTTPHandler
   class. Subsequent tests (e.g. hosted_vllm embedding) created
   client = HTTPHandler() from the new class, but llm_http_handler.py
   still held the old class reference. isinstance(client, HTTPHandler)
   returned False, so a new unpatched client was used and
   client.post was never called.

2. test_vertex_ai_rerank_integration.py reloaded
   litellm.llms.vertex_ai.rerank.transformation in setup_method,
   creating a new VertexAIRerankConfig class. The transformation test
   file's module-level import still referenced the old class, so
   @patch('...VertexAIRerankConfig._ensure_access_token') patched the
   new class while self.config was an instance of the old class,
   leaving the mock unapplied and hitting real Google credentials.

Fix: remove the reload calls. The module-level class references are
stable across tests within a worker; the reloads were solving a problem
that doesn't exist and actively created cross-test contamination.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-17 20:31:10 -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
John GreekandGitHub aa4b0e0149 Fix duplicate test_handler.py filenames causing pytest collection errors (#19385) 2026-01-21 08:47:50 -08:00
YutaSaitoandGitHub eec4ed640b Revert "Stabilise mock tests" 2026-01-17 06:26:18 +09:00
Sameer Kankute 83e33944ef Fix: mock test tests 2026-01-15 22:02:42 +05:30
Sameer Kankute f28d951202 Fix: tests/test_litellm/proxy/test_litellm_pre_call_utils.py::test_embedding_header_forwarding_with_model_group 2026-01-15 19:41:16 +05:30
Sean WalkerandGitHub 29dc4e51f9 Fix HuggingFace embeddings using non-default input_type (#11452)
* fix(huggingface): use get() instead of pop() for input_type parameter

Fixes embedding generation for HuggingFace models where input_type override
is required (e.g. BAAI/bge-m3). The pop() method was mutating optional_params
and removing input_type before downstream functions could access it.

* Add unit tests to catch regression

* Move tests around
2025-06-05 15:48:55 -07:00