From 4a8669325453bb7402fba76e1f14a410a7be48c0 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 26 Jun 2024 09:41:16 +0200 Subject: [PATCH] Verify default timezone is restored when test ends (#116216) --- tests/conftest.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 1d4699647c9..161ff458ac0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,6 +5,7 @@ from __future__ import annotations import asyncio from collections.abc import Callable, Coroutine from contextlib import asynccontextmanager, contextmanager +import datetime import functools import gc import itertools @@ -76,7 +77,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.translation import _TranslationsCacheData from homeassistant.helpers.typing import ConfigType from homeassistant.setup import BASE_PLATFORMS, async_setup_component -from homeassistant.util import location +from homeassistant.util import dt as dt_util, location from homeassistant.util.async_ import create_eager_task from homeassistant.util.json import json_loads @@ -385,6 +386,13 @@ def verify_cleanup( "waitpid-" ) + try: + # Verify the default time zone has been restored + assert dt_util.DEFAULT_TIME_ZONE is datetime.UTC + finally: + # Restore the default time zone to not break subsequent tests + dt_util.DEFAULT_TIME_ZONE = datetime.UTC + @pytest.fixture(autouse=True) def reset_hass_threading_local_object() -> Generator[None]: