Skip to content

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]

Fixing test

yuneng-jiangd99cf813867e
diff --git a/tests/test_litellm/proxy/test_proxy_server.py b/tests/test_litellm/proxy/test_proxy_server.py
index 87f44464cf8..1b7d285bf33 100644
--- a/tests/test_litellm/proxy/test_proxy_server.py
+++ b/tests/test_litellm/proxy/test_proxy_server.py
@@ -2621,26 +2621,37 @@ def test_get_prompt_spec_for_db_prompt_with_versions():
def test_root_redirect_when_docs_url_not_root_and_redirect_url_set(monkeypatch):
from litellm.proxy.proxy_server import cleanup_router_config_variables
+ from litellm.proxy.utils import _get_docs_url
from fastapi.responses import RedirectResponse
cleanup_router_config_variables()
filepath = os.path.dirname(os.path.abspath(__file__))
config_fp = f"{filepath}/test_configs/test_config_no_auth.yaml"
+ # Ensure docs are mounted on a non-root path to trigger redirect logic
+ monkeypatch.setenv("DOCS_URL", "/docs")
test_redirect_url = "/ui"
monkeypatch.setenv("ROOT_REDIRECT_URL", test_redirect_url)
asyncio.run(initialize(config=config_fp, debug=True))
- docs_url = getattr(app, "docs_url", None) or "/docs"
+ docs_url = _get_docs_url()
root_redirect_url = os.getenv("ROOT_REDIRECT_URL")
+ # Remove any existing "/" route that might interfere
+ routes_to_remove = []
+ for route in app.routes:
+ if hasattr(route, "path") and route.path == "/":
+ if hasattr(route, "methods") and "GET" in route.methods:
+ routes_to_remove.append(route)
+ elif not hasattr(route, "methods"): # Catch-all routes
+ routes_to_remove.append(route)
+
+ for route in routes_to_remove:
+ app.routes.remove(route)
+
+ # Add the redirect route if conditions are met (matching the actual implementation)
if docs_url != "/" and root_redirect_url:
- for route in app.routes:
- if hasattr(route, "path") and route.path == "/" and hasattr(route, "methods") and "GET" in route.methods:
- app.routes.remove(route)
- break
-
@app.get("/", include_in_schema=False)
async def root_redirect():
return RedirectResponse(url=root_redirect_url)