The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test(response_metadata): make the detailed-timing receive-anchor test timezone independent (#42429)
devin-ai-integration[bot]4b65ef6d64e4
diff --git a/tests/unit/litellm_core_utils/llm_response_utils/test_response_metadata.py b/tests/unit/litellm_core_utils/llm_response_utils/test_response_metadata.pyindex 37201e8155b..6f297e6e06a 100644--- a/tests/unit/litellm_core_utils/llm_response_utils/test_response_metadata.py+++ b/tests/unit/litellm_core_utils/llm_response_utils/test_response_metadata.py@@ -7,6 +7,8 @@ through _hidden_params to the x-litellm-callback-duration-ms response header.import asyncioimport datetime+import time+from collections.abc import Iteratorfrom typing import Finalfrom unittest.mock import MagicMock@@ -427,6 +429,15 @@ class TestCallbackDurationInCustomHeaders:assert "x-litellm-callback-duration-ms" not in headers[email protected](params=["UTC", "Asia/Kolkata", "America/Los_Angeles"])+def process_timezone(request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch) -> Iterator[str]:+ monkeypatch.setenv("TZ", request.param)+ time.tzset()+ yield request.param+ monkeypatch.undo()+ time.tzset()++class TestDetailedTiming:"""Tests for detailed per-phase timing headers behind LITELLM_DETAILED_TIMING."""@@ -472,13 +483,14 @@ class TestDetailedTiming:assert hidden.get("timing_pre_processing_ms") == 20.0assert hidden.get("timing_post_processing_ms") == 10.0 # 530 - 20 - 500- def test_detailed_timing_pre_processing_uses_receive_anchor(self, monkeypatch):+ @pytest.mark.skipif(not hasattr(time, "tzset"), reason="switching the process timezone needs time.tzset()")+ def test_detailed_timing_pre_processing_uses_receive_anchor(self, monkeypatch, process_timezone: str):monkeypatch.setattr(response_metadata_mod, "LITELLM_DETAILED_TIMING", True)result = ModelResponse()received_at = datetime.datetime(2025, 1, 1, tzinfo=datetime.timezone.utc)start = received_at + datetime.timedelta(milliseconds=200)- api_call_start = start.replace(tzinfo=None)+ api_call_start = start.astimezone().replace(tzinfo=None)end = start + datetime.timedelta(milliseconds=530)logging_obj = self._make_logging_obj(llm_api_duration_ms=500.0,