Files
crewAI/tests/test_dependency_compatibility.py
2025-04-03 17:35:00 +00:00

86 lines
2.7 KiB
Python

"""
Dependency Compatibility Tests
Tests to verify compatibility between litellm and other packages that depend on httpx.
Known working versions:
- httpx >= 0.28.1
- litellm >= 1.65.1
- exa-py (optional)
- google-genai (optional)
"""
import importlib.util
import sys
import pytest
def _check_optional_dependency(package_name):
"""Centralized handling of optional dependency checks"""
if importlib.util.find_spec(package_name) is None:
pytest.skip(f"{package_name} not installed. Skipping compatibility test.")
return True
@pytest.fixture(autouse=True)
def log_versions():
"""Log all relevant package versions before tests"""
import httpx
import litellm
versions = {
"httpx": httpx.__version__,
}
print("\nRunning tests with versions:", versions)
return versions
class TestDependencyCompatibility:
"""Test suite for checking package dependency compatibility"""
def test_httpx_litellm_compatibility(self):
"""Test that litellm is compatible with the latest httpx"""
import httpx
import litellm
try:
assert hasattr(httpx, "__version__")
min_required_version = "0.28.1" # Minimum required version
from packaging import version
assert version.parse(httpx.__version__) >= version.parse(min_required_version)
except (AssertionError, ImportError) as e:
pytest.fail(f"httpx version {httpx.__version__} is not compatible. Minimum required: {min_required_version}. Error: {e}")
print(f"Using httpx version: {httpx.__version__}")
print("Successfully imported litellm")
def test_exa_py_compatibility(self):
"""Test that exa-py can be imported alongside litellm"""
_check_optional_dependency("exa")
import exa
import httpx
import litellm
assert hasattr(exa, "__version__")
assert hasattr(httpx, "__version__")
print(f"Using exa-py version: {exa.__version__}")
print("Successfully imported litellm")
print(f"Using httpx version: {httpx.__version__}")
def test_google_genai_compatibility(self):
"""Test that google-genai can be imported alongside litellm"""
_check_optional_dependency("google.generativeai")
import httpx
import litellm
from google import generativeai
assert hasattr(generativeai, "version")
assert hasattr(httpx, "__version__")
print(f"Using google-genai version: {generativeai.version}")
print("Successfully imported litellm")
print(f"Using httpx version: {httpx.__version__}")