From 148eb996aee0a8490ab34b761ef6537c19243c75 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Sat, 11 May 2024 20:09:00 +0200 Subject: [PATCH] Use mock_config_flow helper in config tests (#117245) --- .../components/config/test_config_entries.py | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/tests/components/config/test_config_entries.py b/tests/components/config/test_config_entries.py index b624205ce853b..f5eca8b7b467c 100644 --- a/tests/components/config/test_config_entries.py +++ b/tests/components/config/test_config_entries.py @@ -22,6 +22,7 @@ MockConfigEntry, MockModule, MockUser, + mock_config_flow, mock_integration, mock_platform, ) @@ -49,7 +50,25 @@ async def client(hass, hass_client) -> TestClient: return await hass_client() -async def test_get_entries(hass: HomeAssistant, client, clear_handlers) -> None: +@pytest.fixture +async def mock_flow(): + """Mock a config flow.""" + + class Comp1ConfigFlow(ConfigFlow): + """Config flow with options flow.""" + + @staticmethod + @callback + def async_get_options_flow(config_entry): + """Get options flow.""" + + with mock_config_flow("comp1", Comp1ConfigFlow): + yield + + +async def test_get_entries( + hass: HomeAssistant, client, clear_handlers, mock_flow +) -> None: """Test get entries.""" mock_integration(hass, MockModule("comp1")) mock_integration( @@ -65,21 +84,6 @@ async def test_get_entries(hass: HomeAssistant, client, clear_handlers) -> None: hass, MockModule("comp5", partial_manifest={"integration_type": "service"}) ) - @HANDLERS.register("comp1") - class Comp1ConfigFlow: - """Config flow with options flow.""" - - @staticmethod - @callback - def async_get_options_flow(config_entry): - """Get options flow.""" - - @classmethod - @callback - def async_supports_options_flow(cls, config_entry): - """Return options flow support for this handler.""" - return True - config_entry_flow.register_discovery_flow("comp2", "Comp 2", lambda: None) entry = MockConfigEntry(