All new functionality must include mock tests placed in the `tests/litellm/` directory structure. Mock external API calls and dependencies rather than requiring real credentials or external services. This ensures tests can run reliably in CI/CD pipelines and are accessible to all contributors.
All new functionality must include mock tests placed in the tests/litellm/
directory structure. Mock external API calls and dependencies rather than requiring real credentials or external services. This ensures tests can run reliably in CI/CD pipelines and are accessible to all contributors.
Key Requirements:
tests/litellm/
following the source code structure (e.g., tests/litellm/llms/provider_name/
)unittest.mock
or pytest-mock
instead of making real API requestsMagicMock
to simulate responses from external servicesExample:
# Good: Mock test in tests/litellm/
from unittest.mock import patch, MagicMock
import pytest
from litellm import completion
def test_provider_completion_mock():
mock_response = MagicMock()
mock_response.json.return_value = {
"choices": [{"message": {"content": "Hello"}}]
}
with patch("requests.post", return_value=mock_response):
response = completion(
model="provider/model-name",
messages=[{"role": "user", "content": "Hi"}]
)
assert response.choices[0].message.content == "Hello"
# Bad: Integration test requiring real credentials
def test_provider_completion_real():
# Requires PROVIDER_API_KEY environment variable
response = completion(
model="provider/model-name",
messages=[{"role": "user", "content": "Hi"}]
)
This approach prevents test failures due to missing credentials, network issues, or rate limits, while ensuring comprehensive test coverage that contributors can run locally and in automated pipelines.
Enter the URL of a public GitHub repository