Files
litellm/tests/test_litellm
shin-bot-litellm 37a45a3295 litellm_fix_mapped_tests_core: clear client cache and fix isinstance checks (#20196)
## Problem
Tests using mocked HTTP clients were hitting real APIs because:
1. HTTP client cache was returning previously cached real clients
2. isinstance checks failed due to module identity issues from sys.path

### Tests affected:
- test_send_email_missing_api_key
- test_send_email_multiple_recipients (resend & sendgrid)
- test_search_uses_registry_credentials
- test_vector_store_create_with_simple_provider_name
- test_vector_store_create_with_provider_api_type
- test_vector_store_create_with_ragflow_provider
- test_image_edit_merges_headers_and_extra_headers
- test_retrieve_container_basic (container API tests)

## Solution
1. Add clear_client_cache fixture (autouse=True) to clear
   litellm.in_memory_llm_clients_cache before each test
2. Fix isinstance checks to use type name comparison
   (avoids module identity issues from sys.path.insert)

## Why not disable_aiohttp_transport
The default transport is aiohttp, so tests should work with it.
Clearing the cache ensures mocks are used instead of cached real clients.

## Regression
PR #19829 (commit f95572e3ed) added @respx.mock but cached clients
from earlier tests were being reused, bypassing the mocks.

Co-authored-by: shin-bot-litellm <shin-bot-litellm@users.noreply.github.com>
2026-01-31 15:42:17 -08:00
..
2026-01-24 11:13:44 -08:00
2026-01-24 14:08:48 -08:00

Testing for litellm/

This directory 1:1 maps the the litellm/ directory, and can only contain mocked tests.

The point of this is to:

  1. Increase test coverage of litellm/
  2. Make it easy for contributors to add tests for the litellm/ package and easily run tests without needing LLM API keys.

File name conventions

  • litellm/proxy/test_caching_routes.py maps to litellm/proxy/caching_routes.py
  • test_<filename>.py maps to litellm/<filename>.py