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 <erik@montnemery.com>

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
epenet 2025-03-06 13:57:13 +01:00 committed by GitHub
parent 1a4a3a0f08
commit 377e0a64d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 9 additions and 30 deletions

View File

@ -1,7 +1,6 @@
"""Test for the alarm control panel const module.""" """Test for the alarm control panel const module."""
from typing import Any from typing import Any
from unittest.mock import patch
import pytest import pytest
@ -23,7 +22,7 @@ from homeassistant.const import (
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceValidationError 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 homeassistant.helpers.typing import UNDEFINED, UndefinedType
from . import help_async_setup_entry_init, help_async_unload_entry 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") 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( async def test_alarm_control_panel_not_log_deprecated_state_warning(
hass: HomeAssistant, hass: HomeAssistant,
mock_alarm_control_panel_entity: MockAlarmControlPanel, 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") @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( async def test_alarm_control_panel_log_deprecated_state_warning_using_state_prop(
hass: HomeAssistant, hass: HomeAssistant,
code_format: CodeFormat | None, 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") @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( async def test_alarm_control_panel_log_deprecated_state_warning_using_attr_state_attr(
hass: HomeAssistant, hass: HomeAssistant,
code_format: CodeFormat | None, 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") @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( async def test_alarm_control_panel_deprecated_state_does_not_break_state(
hass: HomeAssistant, hass: HomeAssistant,
code_format: CodeFormat | None, code_format: CodeFormat | None,

View File

@ -21,7 +21,6 @@ from homeassistant.const import (
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError, Unauthorized from homeassistant.exceptions import HomeAssistantError, Unauthorized
from homeassistant.helpers import frame
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from homeassistant.util import color as color_util 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"], ids=["with_kelvin", "with_mired_values", "with_mired_defaults"],
) )
@patch.object(frame, "_REPORTED_INTEGRATIONS", set())
def test_missing_kelvin_property_warnings( def test_missing_kelvin_property_warnings(
hass: HomeAssistant, hass: HomeAssistant,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,

View File

@ -114,7 +114,6 @@ async def test_async_resolve_media(hass: HomeAssistant) -> None:
assert media.mime_type == "audio/mpeg" assert media.mime_type == "audio/mpeg"
@patch("homeassistant.helpers.frame._REPORTED_INTEGRATIONS", set())
async def test_async_resolve_media_no_entity( async def test_async_resolve_media_no_entity(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None: ) -> None:

View File

@ -5,7 +5,6 @@ from __future__ import annotations
from enum import Enum from enum import Enum
from types import ModuleType from types import ModuleType
from typing import Any from typing import Any
from unittest.mock import patch
import pytest import pytest
@ -25,7 +24,6 @@ from homeassistant.components.vacuum import (
VacuumEntityFeature, VacuumEntityFeature,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import frame
from . import MockVacuum, help_async_setup_entry_init, help_async_unload_entry from . import MockVacuum, help_async_setup_entry_init, help_async_unload_entry
from .common import async_start 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") @pytest.mark.usefixtures("mock_as_custom_component")
@patch.object(frame, "_REPORTED_INTEGRATIONS", set())
async def test_vacuum_log_deprecated_state_warning_using_state_prop( async def test_vacuum_log_deprecated_state_warning_using_state_prop(
hass: HomeAssistant, hass: HomeAssistant,
config_flow_fixture: None, 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") @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( async def test_vacuum_log_deprecated_state_warning_using_attr_state_attr(
hass: HomeAssistant, hass: HomeAssistant,
config_flow_fixture: None, 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") @pytest.mark.usefixtures("mock_as_custom_component")
@patch.object(frame, "_REPORTED_INTEGRATIONS", set())
async def test_vacuum_deprecated_state_does_not_break_state( async def test_vacuum_deprecated_state_does_not_break_state(
hass: HomeAssistant, hass: HomeAssistant,
config_flow_fixture: None, config_flow_fixture: None,

View File

@ -430,11 +430,16 @@ def verify_cleanup(
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def reset_hass_threading_local_object() -> Generator[None]: def reset_globals() -> Generator[None]:
"""Reset the _Hass threading.local object for every test case.""" """Reset global objects for every test case."""
yield yield
# Reset the _Hass threading.local object
ha._hass.__dict__.clear() ha._hass.__dict__.clear()
# Reset the frame helper globals
frame.async_setup(None) frame.async_setup(None)
frame._REPORTED_INTEGRATIONS.clear()
@pytest.fixture(autouse=True, scope="session") @pytest.fixture(autouse=True, scope="session")

View File

@ -249,7 +249,6 @@ async def test_get_clientsession_patched_close(hass: HomeAssistant) -> None:
assert mock_close.call_count == 0 assert mock_close.call_count == 0
@patch("homeassistant.helpers.frame._REPORTED_INTEGRATIONS", set())
async def test_warning_close_session_integration( async def test_warning_close_session_integration(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None: ) -> None:
@ -292,7 +291,6 @@ async def test_warning_close_session_integration(
) in caplog.text ) in caplog.text
@patch("homeassistant.helpers.frame._REPORTED_INTEGRATIONS", set())
async def test_warning_close_session_custom( async def test_warning_close_session_custom(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None: ) -> None:

View File

@ -376,7 +376,6 @@ async def test_report_usage_find_issue_tracker_other_thread(
assert reports == snapshot assert reports == snapshot
@patch.object(frame, "_REPORTED_INTEGRATIONS", set())
@pytest.mark.usefixtures("hass", "mock_integration_frame") @pytest.mark.usefixtures("hass", "mock_integration_frame")
async def test_prevent_flooding( async def test_prevent_flooding(
caplog: pytest.LogCaptureFixture, mock_integration_frame: Mock caplog: pytest.LogCaptureFixture, mock_integration_frame: Mock
@ -408,7 +407,6 @@ async def test_prevent_flooding(
assert len(frame._REPORTED_INTEGRATIONS) == 1 assert len(frame._REPORTED_INTEGRATIONS) == 1
@patch.object(frame, "_REPORTED_INTEGRATIONS", set())
@pytest.mark.usefixtures("hass", "mock_integration_frame") @pytest.mark.usefixtures("hass", "mock_integration_frame")
async def test_breaks_in_ha_version( async def test_breaks_in_ha_version(
caplog: pytest.LogCaptureFixture, mock_integration_frame: Mock caplog: pytest.LogCaptureFixture, mock_integration_frame: Mock

View File

@ -100,7 +100,6 @@ async def test_get_async_client_context_manager(hass: HomeAssistant) -> None:
assert mock_aclose.call_count == 0 assert mock_aclose.call_count == 0
@patch("homeassistant.helpers.frame._REPORTED_INTEGRATIONS", set())
async def test_warning_close_session_integration( async def test_warning_close_session_integration(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None: ) -> None:
@ -144,7 +143,6 @@ async def test_warning_close_session_integration(
) in caplog.text ) in caplog.text
@patch("homeassistant.helpers.frame._REPORTED_INTEGRATIONS", set())
async def test_warning_close_session_custom( async def test_warning_close_session_custom(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None: ) -> None:

View File

@ -19,7 +19,7 @@ from homeassistant.exceptions import (
ConfigEntryError, ConfigEntryError,
ConfigEntryNotReady, ConfigEntryNotReady,
) )
from homeassistant.helpers import frame, update_coordinator from homeassistant.helpers import update_coordinator
from homeassistant.util.dt import utcnow from homeassistant.util.dt import utcnow
from tests.common import MockConfigEntry, async_fire_time_changed 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") @pytest.mark.usefixtures("mock_integration_frame")
@patch.object(frame, "_REPORTED_INTEGRATIONS", set())
async def test_async_config_entry_first_refresh_invalid_state_in_integration( async def test_async_config_entry_first_refresh_invalid_state_in_integration(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None: ) -> None:

View File

@ -5763,7 +5763,6 @@ async def test_reauth_reconfigure_missing_entry(
@pytest.mark.usefixtures("mock_integration_frame") @pytest.mark.usefixtures("mock_integration_frame")
@patch.object(frame, "_REPORTED_INTEGRATIONS", set())
@pytest.mark.parametrize( @pytest.mark.parametrize(
"source", [config_entries.SOURCE_REAUTH, config_entries.SOURCE_RECONFIGURE] "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.parametrize("integration_frame_path", ["custom_components/my_integration"])
@pytest.mark.usefixtures("hass", "mock_integration_frame") @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: async def test_options_flow_with_config_entry(caplog: pytest.LogCaptureFixture) -> None:
"""Test that OptionsFlowWithConfigEntry doesn't mutate entry options.""" """Test that OptionsFlowWithConfigEntry doesn't mutate entry options."""
entry = MockConfigEntry( 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.parametrize("integration_frame_path", ["custom_components/my_integration"])
@pytest.mark.usefixtures("mock_integration_frame") @pytest.mark.usefixtures("mock_integration_frame")
@patch.object(frame, "_REPORTED_INTEGRATIONS", set())
async def test_options_flow_deprecated_config_entry_setter( async def test_options_flow_deprecated_config_entry_setter(
hass: HomeAssistant, hass: HomeAssistant,
manager: config_entries.ConfigEntries, manager: config_entries.ConfigEntries,

View File

@ -15,7 +15,6 @@ from homeassistant import loader
from homeassistant.components import http, hue from homeassistant.components import http, hue
from homeassistant.components.hue import light as hue_light from homeassistant.components.hue import light as hue_light
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import frame
from homeassistant.helpers.json import json_dumps from homeassistant.helpers.json import json_dumps
from homeassistant.util.json import json_loads 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") @pytest.mark.usefixtures("mock_integration_frame")
@patch.object(frame, "_REPORTED_INTEGRATIONS", set())
async def test_hass_components_use_reported( async def test_hass_components_use_reported(
hass: HomeAssistant, hass: HomeAssistant,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
@ -2010,7 +2008,6 @@ async def test_has_services(hass: HomeAssistant) -> None:
], ],
) )
@pytest.mark.usefixtures("mock_integration_frame") @pytest.mark.usefixtures("mock_integration_frame")
@patch.object(frame, "_REPORTED_INTEGRATIONS", set())
async def test_hass_helpers_use_reported( async def test_hass_helpers_use_reported(
hass: HomeAssistant, hass: HomeAssistant,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,