mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
fixing no_config test
This commit is contained in:
parent
349e3dad55
commit
efe84777e5
1 changed files with 31 additions and 5 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue