From 15976b82077f5a9153fbd3c2c94fad6f399b8c0b Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 20 Aug 2024 14:53:06 +0200 Subject: [PATCH] Disable expensive pskc computation in all otbr tests (#124292) * Disable expensive pskc computation in all otbr tests * Update tests and fixtures which patched compute_pskc --- tests/components/otbr/conftest.py | 23 +++++++++++++++++++---- tests/components/otbr/test_init.py | 6 ++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/tests/components/otbr/conftest.py b/tests/components/otbr/conftest.py index 8344c734572..fdd5b93d6cd 100644 --- a/tests/components/otbr/conftest.py +++ b/tests/components/otbr/conftest.py @@ -20,6 +20,23 @@ from . import ( from tests.common import MockConfigEntry +@pytest.fixture(name="enable_compute_pskc") +def enable_compute_pskc_fixture() -> Any: + """Allow controlling if compute_pskc should be enabled.""" + return False + + +@pytest.fixture(name="compute_pskc", autouse=True) +def compute_pskc_fixture(enable_compute_pskc: bool) -> Any: + """Patch homeassistant.components.otbr.util.compute_pskc.""" + compute_pskc = otbr.util.compute_pskc if enable_compute_pskc else None + + with patch( + "homeassistant.components.otbr.util.compute_pskc", side_effect=compute_pskc + ) as compute_pskc_mock: + yield compute_pskc_mock + + @pytest.fixture(name="dataset") def dataset_fixture() -> Any: """Return the discovery info from the supervisor.""" @@ -76,8 +93,7 @@ async def otbr_config_entry_multipan_fixture(hass: HomeAssistant) -> None: "python_otbr_api.OTBR.get_extended_address", return_value=TEST_BORDER_AGENT_EXTENDED_ADDRESS, ), - patch("homeassistant.components.otbr.util.compute_pskc"), - ): # Patch to speed up tests + ): assert await hass.config_entries.async_setup(config_entry.entry_id) @@ -103,8 +119,7 @@ async def otbr_config_entry_thread_fixture(hass: HomeAssistant) -> None: "python_otbr_api.OTBR.get_extended_address", return_value=TEST_BORDER_AGENT_EXTENDED_ADDRESS, ), - patch("homeassistant.components.otbr.util.compute_pskc"), - ): # Patch to speed up tests + ): assert await hass.config_entries.async_setup(config_entry.entry_id) diff --git a/tests/components/otbr/test_init.py b/tests/components/otbr/test_init.py index 7d54dd16f56..86bab71cbda 100644 --- a/tests/components/otbr/test_init.py +++ b/tests/components/otbr/test_init.py @@ -198,6 +198,7 @@ async def test_import_share_radio_no_channel_collision( ) +@pytest.mark.parametrize("enable_compute_pskc", [True]) @pytest.mark.parametrize( "dataset", [DATASET_INSECURE_NW_KEY, DATASET_INSECURE_PASSPHRASE] ) @@ -333,8 +334,5 @@ async def test_remove_extra_entries( config_entry1.add_to_hass(hass) config_entry2.add_to_hass(hass) assert len(hass.config_entries.async_entries(otbr.DOMAIN)) == 2 - with ( - patch("homeassistant.components.otbr.util.compute_pskc"), - ): # Patch to speed up tests - assert await async_setup_component(hass, otbr.DOMAIN, {}) + assert await async_setup_component(hass, otbr.DOMAIN, {}) assert len(hass.config_entries.async_entries(otbr.DOMAIN)) == 1