diff --git a/tests/components/insteon/mock_devices.py b/tests/components/insteon/mock_devices.py index 05db45d00ac4..732829098db8 100644 --- a/tests/components/insteon/mock_devices.py +++ b/tests/components/insteon/mock_devices.py @@ -138,7 +138,8 @@ class MockDevices: device = self._devices[Address(address)] aldb_records = dict_to_aldb_record(records) - device.aldb.load_saved_records(ALDBStatus.LOADED, aldb_records) + with patch("pyinsteon.aldb.aldb_base.publish_topic", MagicMock()): + device.aldb.load_saved_records(ALDBStatus.LOADED, aldb_records) def fill_properties(self, address, props_dict): """Fill the operating flags and extended properties of a device.""" diff --git a/tests/components/insteon/test_api_aldb.py b/tests/components/insteon/test_api_aldb.py index 5060808db2b8..dcac95ac38a4 100644 --- a/tests/components/insteon/test_api_aldb.py +++ b/tests/components/insteon/test_api_aldb.py @@ -82,8 +82,6 @@ def _aldb_dict(mem_addr): } -# This tests needs to be adjusted to remove lingering tasks -@pytest.mark.parametrize("expected_lingering_tasks", [True]) async def test_get_aldb( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, aldb_data ) -> None: @@ -100,8 +98,6 @@ async def test_get_aldb( assert len(result) == 5 -# This tests needs to be adjusted to remove lingering tasks -@pytest.mark.parametrize("expected_lingering_tasks", [True]) async def test_change_aldb_record( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, aldb_data ) -> None: @@ -125,8 +121,6 @@ async def test_change_aldb_record( _compare_records(rec, change_rec) -# This tests needs to be adjusted to remove lingering tasks -@pytest.mark.parametrize("expected_lingering_tasks", [True]) async def test_create_aldb_record( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, aldb_data ) -> None: @@ -150,8 +144,6 @@ async def test_create_aldb_record( _compare_records(rec, new_rec) -# This tests needs to be adjusted to remove lingering tasks -@pytest.mark.parametrize("expected_lingering_tasks", [True]) async def test_write_aldb( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, aldb_data ) -> None: @@ -173,8 +165,6 @@ async def test_write_aldb( assert devices.async_save.call_count == 1 -# This tests needs to be adjusted to remove lingering tasks -@pytest.mark.parametrize("expected_lingering_tasks", [True]) async def test_load_aldb( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, aldb_data ) -> None: @@ -195,8 +185,6 @@ async def test_load_aldb( assert devices.async_save.call_count == 1 -# This tests needs to be adjusted to remove lingering tasks -@pytest.mark.parametrize("expected_lingering_tasks", [True]) async def test_reset_aldb( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, aldb_data ) -> None: @@ -228,8 +216,6 @@ async def test_reset_aldb( assert not devices["33.33.33"].aldb.pending_changes -# This tests needs to be adjusted to remove lingering tasks -@pytest.mark.parametrize("expected_lingering_tasks", [True]) async def test_default_links( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, aldb_data ) -> None: @@ -305,8 +291,6 @@ async def test_notify_on_aldb_record_added( assert msg["event"]["type"] == "record_loaded" -# This tests needs to be adjusted to remove lingering tasks -@pytest.mark.parametrize("expected_lingering_tasks", [True]) async def test_bad_address( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, aldb_data ) -> None: diff --git a/tests/components/insteon/test_api_config.py b/tests/components/insteon/test_api_config.py index b3eb5e302929..a5017c496da7 100644 --- a/tests/components/insteon/test_api_config.py +++ b/tests/components/insteon/test_api_config.py @@ -1,6 +1,5 @@ """Test the Insteon APIs for configuring the integration.""" -import asyncio from unittest.mock import patch from homeassistant.components import insteon @@ -406,7 +405,6 @@ async def test_get_broken_links( await devices.async_load() aldb_data = await async_load_json_object_fixture(hass, "aldb_data.json", DOMAIN) devices.fill_aldb("33.33.33", aldb_data) - await asyncio.sleep(1) with patch.object(insteon.api.config, "devices", devices): await ws_client.send_json({ID: 2, TYPE: "insteon/config/get_broken_links"}) msg = await ws_client.receive_json() @@ -445,4 +443,3 @@ async def test_get_unknown_devices( assert msg["success"] assert len(msg["result"]) == 1 - await asyncio.sleep(0.1) diff --git a/tests/components/insteon/test_api_properties.py b/tests/components/insteon/test_api_properties.py index b792066271da..2c6da4238258 100644 --- a/tests/components/insteon/test_api_properties.py +++ b/tests/components/insteon/test_api_properties.py @@ -1,7 +1,7 @@ """Test the Insteon properties APIs.""" from typing import Any -from unittest.mock import AsyncMock, patch +from unittest.mock import AsyncMock, MagicMock, patch from pyinsteon.config import MOMENTARY_DELAY, RELAY_MODE, TOGGLE_BUTTON from pyinsteon.config.extended_property import ExtendedProperty @@ -125,7 +125,9 @@ async def test_get_read_only_properties( mock_read_only = ExtendedProperty( "44.44.44", "mock_read_only", bool, is_read_only=True ) - mock_read_only.set_value(False) + # Publishing the change would spawn status handler tasks that outlive the test + with patch("pyinsteon.subscriber_base.publish_topic", MagicMock()): + mock_read_only.set_value(False) ws_client, devices = await _setup( hass, hass_ws_client, "44.44.44", iolinc_properties_data diff --git a/tests/components/insteon/test_api_scenes.py b/tests/components/insteon/test_api_scenes.py index 14001e0495d7..22ee1b140bbe 100644 --- a/tests/components/insteon/test_api_scenes.py +++ b/tests/components/insteon/test_api_scenes.py @@ -64,8 +64,6 @@ async def _setup( return ws_client, devices -# This tests needs to be adjusted to remove lingering tasks -@pytest.mark.parametrize("expected_lingering_tasks", [True]) async def test_get_scenes( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, scene_data: JsonArrayType ) -> None: @@ -80,8 +78,6 @@ async def test_get_scenes( assert len(result["20"]) == 3 -# This tests needs to be adjusted to remove lingering tasks -@pytest.mark.parametrize("expected_lingering_tasks", [True]) async def test_get_scene( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, scene_data: JsonArrayType ) -> None: @@ -95,8 +91,6 @@ async def test_get_scene( assert len(result["devices"]) == 3 -# This tests needs to be adjusted to remove lingering tasks -@pytest.mark.parametrize("expected_lingering_tasks", [True]) @pytest.mark.usefixtures("remove_json") async def test_save_scene( hass: HomeAssistant, @@ -130,8 +124,6 @@ async def test_save_scene( assert result["scene_id"] == 20 -# This tests needs to be adjusted to remove lingering tasks -@pytest.mark.parametrize("expected_lingering_tasks", [True]) @pytest.mark.usefixtures("remove_json") async def test_save_new_scene( hass: HomeAssistant, @@ -165,8 +157,6 @@ async def test_save_new_scene( assert result["scene_id"] == 21 -# This tests needs to be adjusted to remove lingering tasks -@pytest.mark.parametrize("expected_lingering_tasks", [True]) @pytest.mark.usefixtures("remove_json") async def test_save_scene_error( hass: HomeAssistant, @@ -200,8 +190,6 @@ async def test_save_scene_error( assert result["scene_id"] == 20 -# This tests needs to be adjusted to remove lingering tasks -@pytest.mark.parametrize("expected_lingering_tasks", [True]) @pytest.mark.usefixtures("remove_json") async def test_delete_scene( hass: HomeAssistant,