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.
This commit is contained in:
Ishaan Jaff
2026-02-21 14:11:18 -08:00
committed by GitHub
parent 6ec16d583d
commit 6acfa1c71d
@@ -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()