From 377e0a64d16ca7c3c8efe1b376a94290f2d5745d Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 6 Mar 2025 13:57:13 +0100 Subject: [PATCH] Reset helpers.frame._REPORTED_INTEGRATIONS in between tests (#139924) * Reset helpers.frame._REPORTED_INTEGRATIONS in between tests * Rename * Apply suggestions from code review Co-authored-by: Erik Montnemery --------- Co-authored-by: Erik Montnemery --- tests/components/alarm_control_panel/test_init.py | 7 +------ tests/components/light/test_init.py | 2 -- tests/components/media_source/test_init.py | 1 - tests/components/vacuum/test_init.py | 5 ----- tests/conftest.py | 9 +++++++-- tests/helpers/test_aiohttp_client.py | 2 -- tests/helpers/test_frame.py | 2 -- tests/helpers/test_httpx_client.py | 2 -- tests/helpers/test_update_coordinator.py | 3 +-- tests/test_config_entries.py | 3 --- tests/test_loader.py | 3 --- 11 files changed, 9 insertions(+), 30 deletions(-) diff --git a/tests/components/alarm_control_panel/test_init.py b/tests/components/alarm_control_panel/test_init.py index 747a9d1a358..01d103d01aa 100644 --- a/tests/components/alarm_control_panel/test_init.py +++ b/tests/components/alarm_control_panel/test_init.py @@ -1,7 +1,6 @@ """Test for the alarm control panel const module.""" from typing import Any -from unittest.mock import patch import pytest @@ -23,7 +22,7 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant from homeassistant.exceptions import ServiceValidationError -from homeassistant.helpers import entity_registry as er, frame +from homeassistant.helpers import entity_registry as er from homeassistant.helpers.typing import UNDEFINED, UndefinedType from . import help_async_setup_entry_init, help_async_unload_entry @@ -222,7 +221,6 @@ async def test_alarm_control_panel_with_default_code( mock_alarm_control_panel_entity.calls_disarm.assert_called_with("1234") -@patch.object(frame, "_REPORTED_INTEGRATIONS", set()) async def test_alarm_control_panel_not_log_deprecated_state_warning( hass: HomeAssistant, mock_alarm_control_panel_entity: MockAlarmControlPanel, @@ -238,7 +236,6 @@ async def test_alarm_control_panel_not_log_deprecated_state_warning( @pytest.mark.usefixtures("mock_as_custom_component") -@patch.object(frame, "_REPORTED_INTEGRATIONS", set()) async def test_alarm_control_panel_log_deprecated_state_warning_using_state_prop( hass: HomeAssistant, code_format: CodeFormat | None, @@ -303,7 +300,6 @@ async def test_alarm_control_panel_log_deprecated_state_warning_using_state_prop @pytest.mark.usefixtures("mock_as_custom_component") -@patch.object(frame, "_REPORTED_INTEGRATIONS", set()) async def test_alarm_control_panel_log_deprecated_state_warning_using_attr_state_attr( hass: HomeAssistant, code_format: CodeFormat | None, @@ -386,7 +382,6 @@ async def test_alarm_control_panel_log_deprecated_state_warning_using_attr_state @pytest.mark.usefixtures("mock_as_custom_component") -@patch.object(frame, "_REPORTED_INTEGRATIONS", set()) async def test_alarm_control_panel_deprecated_state_does_not_break_state( hass: HomeAssistant, code_format: CodeFormat | None, diff --git a/tests/components/light/test_init.py b/tests/components/light/test_init.py index 5bc17ea3e24..29604ce7595 100644 --- a/tests/components/light/test_init.py +++ b/tests/components/light/test_init.py @@ -21,7 +21,6 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError, Unauthorized -from homeassistant.helpers import frame from homeassistant.setup import async_setup_component from homeassistant.util import color as color_util @@ -2846,7 +2845,6 @@ def test_report_invalid_color_modes( ], ids=["with_kelvin", "with_mired_values", "with_mired_defaults"], ) -@patch.object(frame, "_REPORTED_INTEGRATIONS", set()) def test_missing_kelvin_property_warnings( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, diff --git a/tests/components/media_source/test_init.py b/tests/components/media_source/test_init.py index c37e418020b..2c2952068ee 100644 --- a/tests/components/media_source/test_init.py +++ b/tests/components/media_source/test_init.py @@ -114,7 +114,6 @@ async def test_async_resolve_media(hass: HomeAssistant) -> None: assert media.mime_type == "audio/mpeg" -@patch("homeassistant.helpers.frame._REPORTED_INTEGRATIONS", set()) async def test_async_resolve_media_no_entity( hass: HomeAssistant, caplog: pytest.LogCaptureFixture ) -> None: diff --git a/tests/components/vacuum/test_init.py b/tests/components/vacuum/test_init.py index 717a69470b3..967b9672805 100644 --- a/tests/components/vacuum/test_init.py +++ b/tests/components/vacuum/test_init.py @@ -5,7 +5,6 @@ from __future__ import annotations from enum import Enum from types import ModuleType from typing import Any -from unittest.mock import patch import pytest @@ -25,7 +24,6 @@ from homeassistant.components.vacuum import ( VacuumEntityFeature, ) from homeassistant.core import HomeAssistant -from homeassistant.helpers import frame from . import MockVacuum, help_async_setup_entry_init, help_async_unload_entry from .common import async_start @@ -326,7 +324,6 @@ async def test_vacuum_not_log_deprecated_state_warning( @pytest.mark.usefixtures("mock_as_custom_component") -@patch.object(frame, "_REPORTED_INTEGRATIONS", set()) async def test_vacuum_log_deprecated_state_warning_using_state_prop( hass: HomeAssistant, config_flow_fixture: None, @@ -371,7 +368,6 @@ async def test_vacuum_log_deprecated_state_warning_using_state_prop( @pytest.mark.usefixtures("mock_as_custom_component") -@patch.object(frame, "_REPORTED_INTEGRATIONS", set()) async def test_vacuum_log_deprecated_state_warning_using_attr_state_attr( hass: HomeAssistant, config_flow_fixture: None, @@ -429,7 +425,6 @@ async def test_vacuum_log_deprecated_state_warning_using_attr_state_attr( @pytest.mark.usefixtures("mock_as_custom_component") -@patch.object(frame, "_REPORTED_INTEGRATIONS", set()) async def test_vacuum_deprecated_state_does_not_break_state( hass: HomeAssistant, config_flow_fixture: None, diff --git a/tests/conftest.py b/tests/conftest.py index e3313813112..7725189aa53 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -430,11 +430,16 @@ def verify_cleanup( @pytest.fixture(autouse=True) -def reset_hass_threading_local_object() -> Generator[None]: - """Reset the _Hass threading.local object for every test case.""" +def reset_globals() -> Generator[None]: + """Reset global objects for every test case.""" yield + + # Reset the _Hass threading.local object ha._hass.__dict__.clear() + + # Reset the frame helper globals frame.async_setup(None) + frame._REPORTED_INTEGRATIONS.clear() @pytest.fixture(autouse=True, scope="session") diff --git a/tests/helpers/test_aiohttp_client.py b/tests/helpers/test_aiohttp_client.py index 13cb25bc516..6d2a7e7a8bb 100644 --- a/tests/helpers/test_aiohttp_client.py +++ b/tests/helpers/test_aiohttp_client.py @@ -249,7 +249,6 @@ async def test_get_clientsession_patched_close(hass: HomeAssistant) -> None: assert mock_close.call_count == 0 -@patch("homeassistant.helpers.frame._REPORTED_INTEGRATIONS", set()) async def test_warning_close_session_integration( hass: HomeAssistant, caplog: pytest.LogCaptureFixture ) -> None: @@ -292,7 +291,6 @@ async def test_warning_close_session_integration( ) in caplog.text -@patch("homeassistant.helpers.frame._REPORTED_INTEGRATIONS", set()) async def test_warning_close_session_custom( hass: HomeAssistant, caplog: pytest.LogCaptureFixture ) -> None: diff --git a/tests/helpers/test_frame.py b/tests/helpers/test_frame.py index 6a509ffae5c..e99db76dcbc 100644 --- a/tests/helpers/test_frame.py +++ b/tests/helpers/test_frame.py @@ -376,7 +376,6 @@ async def test_report_usage_find_issue_tracker_other_thread( assert reports == snapshot -@patch.object(frame, "_REPORTED_INTEGRATIONS", set()) @pytest.mark.usefixtures("hass", "mock_integration_frame") async def test_prevent_flooding( caplog: pytest.LogCaptureFixture, mock_integration_frame: Mock @@ -408,7 +407,6 @@ async def test_prevent_flooding( assert len(frame._REPORTED_INTEGRATIONS) == 1 -@patch.object(frame, "_REPORTED_INTEGRATIONS", set()) @pytest.mark.usefixtures("hass", "mock_integration_frame") async def test_breaks_in_ha_version( caplog: pytest.LogCaptureFixture, mock_integration_frame: Mock diff --git a/tests/helpers/test_httpx_client.py b/tests/helpers/test_httpx_client.py index 4b9f2fa2bf6..c3b9c1f9de8 100644 --- a/tests/helpers/test_httpx_client.py +++ b/tests/helpers/test_httpx_client.py @@ -100,7 +100,6 @@ async def test_get_async_client_context_manager(hass: HomeAssistant) -> None: assert mock_aclose.call_count == 0 -@patch("homeassistant.helpers.frame._REPORTED_INTEGRATIONS", set()) async def test_warning_close_session_integration( hass: HomeAssistant, caplog: pytest.LogCaptureFixture ) -> None: @@ -144,7 +143,6 @@ async def test_warning_close_session_integration( ) in caplog.text -@patch("homeassistant.helpers.frame._REPORTED_INTEGRATIONS", set()) async def test_warning_close_session_custom( hass: HomeAssistant, caplog: pytest.LogCaptureFixture ) -> None: diff --git a/tests/helpers/test_update_coordinator.py b/tests/helpers/test_update_coordinator.py index 3ad5754dada..5fd9f9e39fd 100644 --- a/tests/helpers/test_update_coordinator.py +++ b/tests/helpers/test_update_coordinator.py @@ -19,7 +19,7 @@ from homeassistant.exceptions import ( ConfigEntryError, ConfigEntryNotReady, ) -from homeassistant.helpers import frame, update_coordinator +from homeassistant.helpers import update_coordinator from homeassistant.util.dt import utcnow from tests.common import MockConfigEntry, async_fire_time_changed @@ -638,7 +638,6 @@ async def test_async_config_entry_first_refresh_invalid_state( @pytest.mark.usefixtures("mock_integration_frame") -@patch.object(frame, "_REPORTED_INTEGRATIONS", set()) async def test_async_config_entry_first_refresh_invalid_state_in_integration( hass: HomeAssistant, caplog: pytest.LogCaptureFixture ) -> None: diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index 190453afe06..d19c3b38650 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -5763,7 +5763,6 @@ async def test_reauth_reconfigure_missing_entry( @pytest.mark.usefixtures("mock_integration_frame") -@patch.object(frame, "_REPORTED_INTEGRATIONS", set()) @pytest.mark.parametrize( "source", [config_entries.SOURCE_REAUTH, config_entries.SOURCE_RECONFIGURE] ) @@ -6010,7 +6009,6 @@ async def test_options_flow_with_config_entry_core() -> None: @pytest.mark.parametrize("integration_frame_path", ["custom_components/my_integration"]) @pytest.mark.usefixtures("hass", "mock_integration_frame") -@patch.object(frame, "_REPORTED_INTEGRATIONS", set()) async def test_options_flow_with_config_entry(caplog: pytest.LogCaptureFixture) -> None: """Test that OptionsFlowWithConfigEntry doesn't mutate entry options.""" entry = MockConfigEntry( @@ -8789,7 +8787,6 @@ async def test_options_flow_config_entry( @pytest.mark.parametrize("integration_frame_path", ["custom_components/my_integration"]) @pytest.mark.usefixtures("mock_integration_frame") -@patch.object(frame, "_REPORTED_INTEGRATIONS", set()) async def test_options_flow_deprecated_config_entry_setter( hass: HomeAssistant, manager: config_entries.ConfigEntries, diff --git a/tests/test_loader.py b/tests/test_loader.py index 8afe800144c..e4c1982781c 100644 --- a/tests/test_loader.py +++ b/tests/test_loader.py @@ -15,7 +15,6 @@ from homeassistant import loader from homeassistant.components import http, hue from homeassistant.components.hue import light as hue_light from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers import frame from homeassistant.helpers.json import json_dumps from homeassistant.util.json import json_loads @@ -1314,7 +1313,6 @@ async def test_config_folder_not_in_path() -> None: ], ) @pytest.mark.usefixtures("mock_integration_frame") -@patch.object(frame, "_REPORTED_INTEGRATIONS", set()) async def test_hass_components_use_reported( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, @@ -2010,7 +2008,6 @@ async def test_has_services(hass: HomeAssistant) -> None: ], ) @pytest.mark.usefixtures("mock_integration_frame") -@patch.object(frame, "_REPORTED_INTEGRATIONS", set()) async def test_hass_helpers_use_reported( hass: HomeAssistant, caplog: pytest.LogCaptureFixture,