From 2f4032a984ff9b69d53fe36414d33e995c3c43a6 Mon Sep 17 00:00:00 2001 From: mateo Date: Fri, 11 Sep 2026 22:29:12 +0000 Subject: [PATCH] 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> --- .../proxy/proxy_server/test_lifecycle.py | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/tests/test_litellm/proxy/proxy_server/test_lifecycle.py b/tests/test_litellm/proxy/proxy_server/test_lifecycle.py index f592e9a8a7d..775e9443653 100644 --- a/tests/test_litellm/proxy/proxy_server/test_lifecycle.py +++ b/tests/test_litellm/proxy/proxy_server/test_lifecycle.py @@ -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"