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 no_config test

yuneng-jiangefe84777e580
diff --git a/tests/test_litellm/proxy/test_proxy_cli.py b/tests/test_litellm/proxy/test_proxy_cli.py
index be91800732b..a18c2dba032 100644
--- a/tests/test_litellm/proxy/test_proxy_cli.py
+++ b/tests/test_litellm/proxy/test_proxy_cli.py
@@ -446,8 +446,24 @@ class TestProxyInitializationHelpers:
mock_proxy_config_instance.get_config = mock_get_config
mock_proxy_config.return_value = mock_proxy_config_instance
- # Ensure DATABASE_URL is not set in the environment
- with patch.dict(os.environ, {"DATABASE_URL": ""}, clear=True):
+ mock_proxy_server_module = MagicMock(app=mock_app)
+
+ # Only remove DATABASE_URL and DIRECT_URL to prevent the database setup
+ # code path from running. Do NOT use clear=True as it removes PATH, HOME,
+ # etc., which causes imports inside run_server to break in CI (the real
+ # litellm.proxy.proxy_server import at line 820 of proxy_cli.py has heavy
+ # side effects that fail without a proper environment).
+ env_overrides = {
+ "DATABASE_URL": "",
+ "DIRECT_URL": "",
+ "IAM_TOKEN_DB_AUTH": "",
+ "USE_AWS_KMS": "",
+ }
+ with patch.dict(os.environ, env_overrides):
+ # Remove DATABASE_URL entirely so the DB setup block is skipped
+ os.environ.pop("DATABASE_URL", None)
+ os.environ.pop("DIRECT_URL", None)
+
with patch.dict(
"sys.modules",
{
@@ -456,7 +472,11 @@ class TestProxyInitializationHelpers:
ProxyConfig=mock_proxy_config,
KeyManagementSettings=mock_key_mgmt,
save_worker_config=mock_save_worker_config,
- )
+ ),
+ # Also mock litellm.proxy.proxy_server to prevent the real
+ # import at line 820 of proxy_cli.py which has heavy side
+ # effects (FastAPI app init, logging setup, etc.)
+ "litellm.proxy.proxy_server": mock_proxy_server_module,
},
), patch(
"litellm.proxy.proxy_cli.ProxyInitializationHelpers._get_default_unvicorn_init_args"
@@ -470,7 +490,10 @@ class TestProxyInitializationHelpers:
# Test with no config parameter (config=None)
result = runner.invoke(run_server, ["--local"])
- assert result.exit_code == 0
+ assert result.exit_code == 0, (
+ f"run_server failed with exit_code={result.exit_code}, "
+ f"output={result.output}, exception={result.exception}"
+ )
# Verify that uvicorn.run was called
mock_uvicorn_run.assert_called_once()
@@ -481,7 +504,10 @@ class TestProxyInitializationHelpers:
# Test with explicit --config None (should behave the same)
result = runner.invoke(run_server, ["--local", "--config", "None"])
- assert result.exit_code == 0
+ assert result.exit_code == 0, (
+ f"run_server failed with exit_code={result.exit_code}, "
+ f"output={result.output}, exception={result.exception}"
+ )
# Verify that uvicorn.run was called again
mock_uvicorn_run.assert_called_once()