The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test mapped test fixes
Ishaan Jaffe0e356e32830
diff --git a/tests/enterprise/conftest.py b/tests/enterprise/conftest.pyindex b3561d8a626..0365bbbcfa0 100644--- a/tests/enterprise/conftest.py+++ b/tests/enterprise/conftest.py@@ -1,5 +1,6 @@# conftest.py+import asyncioimport importlibimport osimport sys@@ -12,6 +13,18 @@ sys.path.insert(import litellm[email protected](scope="session")+def event_loop():+ try:+ loop = asyncio.get_running_loop()+ except RuntimeError:+ loop = asyncio.new_event_loop()+ yield loop+ loop.close()++++@pytest.fixture(scope="function", autouse=True)def setup_and_teardown():"""@@ -35,6 +48,8 @@ def setup_and_teardown():except Exception as e:print(f"Error reloading litellm.proxy.proxy_server: {e}")+ litellm.in_memory_llm_clients_cache.flush_cache()+import asyncioloop = asyncio.get_event_loop_policy().new_event_loop()diff --git a/tests/enterprise/litellm_enterprise/integrations/test_prometheus_unit_tests.py b/tests/enterprise/litellm_enterprise/integrations/test_prometheus_unit_tests.pyindex 8a3238a675e..b06bb5f4752 100644--- a/tests/enterprise/litellm_enterprise/integrations/test_prometheus_unit_tests.py+++ b/tests/enterprise/litellm_enterprise/integrations/test_prometheus_unit_tests.py@@ -1,6 +1,6 @@from unittest.mock import patch-import pytest_asyncio+import pytest_asynciofrom prometheus_client import REGISTRYtry:@@ -8,7 +8,9 @@ try:except Exception:PrometheusLogger = None-import sys, asyncio+import asyncio+import sys+from dotenv import load_dotenvload_dotenv()@@ -17,19 +19,17 @@ import ossys.path.insert(0, os.path.abspath("../..")) # Adds the parent directory to the system-path+from unittest.mock import MagicMock, patch+import pytest-from litellm import Router-from litellm.router_strategy.budget_limiter import RouterBudgetLimiting-from litellm.types.utils import GenericBudgetConfigType, BudgetConfig-from litellm.caching.caching import DualCacheimport litellm-from unittest.mock import MagicMock, patch+from litellm import Router+from litellm.caching.caching import DualCache+from litellm.router_strategy.budget_limiter import RouterBudgetLimitingfrom litellm.router_utils.cooldown_callbacks import router_cooldown_event_callbackfrom litellm.types.router import ModelInfo---+from litellm.types.utils import BudgetConfig, GenericBudgetConfigTypedef compare_metrics(func):@@ -54,14 +54,19 @@ def compare_metrics(func):return wrapper-@pytest_asyncio.fixture(scope="function")-async def prometheus_logger():[email protected](scope="function")+def prometheus_logger():collectors = list(REGISTRY._collector_to_names.keys())for collector in collectors:REGISTRY.unregister(collector)with patch("litellm.proxy.proxy_server.premium_user", True):- yield PrometheusLogger()+ logger = PrometheusLogger()+ # Add the missing async_logging_hook method+ async def async_logging_hook(kwargs, result, call_type):+ return kwargs, result+ logger.async_logging_hook = async_logging_hook+ return logger@pytest.mark.asyncio@@ -79,6 +84,7 @@ async def test_async_prometheus_success_logging_with_callbacks(prometheus_logger)diff = await op()+ await asyncio.sleep(2)assert diff["litellm_requests_metric_total"] == 1.0@@ -129,8 +135,9 @@ async def test_prometheus_metric_tracking():Test that the Prometheus metric for provider budget is tracked correctly"""try:- from litellm_enterprise.integrations.prometheus import PrometheusLoggerfrom unittest.mock import MagicMock++ from litellm_enterprise.integrations.prometheus import PrometheusLoggerexcept Exception:PrometheusLogger = Noneif PrometheusLogger is None: