test: capture the startup warning with caplog instead of patching the logger

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
mateo 2026-09-11 22:29:12 +00:00
parent 107b99c733
commit 2f4032a984

View file

@ -1076,19 +1076,17 @@ async def test_prometheus_fallback_stats_job_runs_when_the_lock_is_free_or_absen
@pytest.mark.asyncio
async def test_proxy_startup_event_warns_but_does_not_raise_for_docs_example_master_key(monkeypatch):
async def test_proxy_startup_event_warns_but_does_not_raise_for_docs_example_master_key(monkeypatch, caplog):
monkeypatch.setenv("LITELLM_MASTER_KEY", "sk-1234")
with patch.object(ps.verbose_proxy_logger, "warning") as mock_warning:
try:
try:
with caplog.at_level(logging.WARNING, logger="LiteLLM Proxy"):
async with proxy_startup_event(app=None):
pass
except ValueError as e:
if "sk-1234" in str(e):
pytest.fail("proxy_startup_event refused to boot on the docs example key")
except Exception:
pass
except ValueError as e:
if "sk-1234" in str(e):
pytest.fail("proxy_startup_event refused to boot on the docs example key")
except Exception:
pass
assert any("sk-1234" in str(call.args[0]) for call in mock_warning.call_args_list), (
"startup should log the insecure master key warning"
)
assert "sk-1234" in caplog.text, "startup should log the insecure master key warning"