From 6acfa1c71dffdfefb3d13b962896c3a7a59dc184 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 21 Feb 2026 14:11:18 -0800 Subject: [PATCH] fix(tests): clear ANTHROPIC_BASE_URL/ANTHROPIC_API_BASE in spend log api_base tests (#21820) Tests hardcode expected api_base as https://api.anthropic.com/v1/messages but if ANTHROPIC_BASE_URL is set in the environment the recorded api_base changes, causing a mismatch. Clear both env vars via monkeypatch at the start of each test. --- .../spend_tracking/test_spend_management_endpoints.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py b/tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py index 97d1d4a2f3..ad61d7ffc9 100644 --- a/tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py +++ b/tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py @@ -1324,6 +1324,10 @@ class TestSpendLogsPayload: async def test_spend_logs_payload_success_log_with_api_base(self, monkeypatch): from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler + # Clear any env overrides that would change the recorded api_base + monkeypatch.delenv("ANTHROPIC_BASE_URL", raising=False) + monkeypatch.delenv("ANTHROPIC_API_BASE", raising=False) + litellm.callbacks = [_ProxyDBLogger(message_logging=False)] # litellm._turn_on_debug() @@ -1397,9 +1401,13 @@ class TestSpendLogsPayload: assert False, f"Dictionary mismatch: {differences}" @pytest.mark.asyncio - async def test_spend_logs_payload_success_log_with_router(self): + async def test_spend_logs_payload_success_log_with_router(self, monkeypatch): from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler + # Clear any env overrides that would change the recorded api_base + monkeypatch.delenv("ANTHROPIC_BASE_URL", raising=False) + monkeypatch.delenv("ANTHROPIC_API_BASE", raising=False) + litellm.callbacks = [_ProxyDBLogger(message_logging=False)] # litellm._turn_on_debug()