From 4b65ef6d64e40253ea6e6ce712eaa6b9c496f69c Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 22 Sep 2026 10:49:37 -0700 Subject: [PATCH] test(response_metadata): make the detailed-timing receive-anchor test timezone independent (#42429) Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com> --- .../llm_response_utils/test_response_metadata.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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.py index 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 asyncio import datetime +import time +from collections.abc import Iterator from typing import Final from unittest.mock import MagicMock @@ -427,6 +429,15 @@ class TestCallbackDurationInCustomHeaders: assert "x-litellm-callback-duration-ms" not in headers +@pytest.fixture(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.0 assert 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,