From ee85a23d1907bb01fa58b27ad7da5223fd5170fa Mon Sep 17 00:00:00 2001 From: jan iversen Date: Mon, 16 Jan 2023 15:44:11 +0100 Subject: [PATCH] Bring modbus back to 100% test coverage (#85972) Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> --- tests/components/modbus/test_init.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/components/modbus/test_init.py b/tests/components/modbus/test_init.py index 3b704eff161..2a212535916 100644 --- a/tests/components/modbus/test_init.py +++ b/tests/components/modbus/test_init.py @@ -862,3 +862,20 @@ async def test_integration_reload( async_fire_time_changed(hass) await hass.async_block_till_done() assert "Modbus reloading" in caplog.text + + +@pytest.mark.parametrize("do_config", [{}]) +async def test_integration_reload_failed(hass, caplog, mock_modbus) -> None: + """Run test for integration connect failure on reload.""" + caplog.set_level(logging.INFO) + caplog.clear() + + yaml_path = get_fixture_path("configuration.yaml", "modbus") + with mock.patch.object( + hass_config, "YAML_CONFIG_FILE", yaml_path + ), mock.patch.object(mock_modbus, "connect", side_effect=ModbusException("error")): + await hass.services.async_call(DOMAIN, SERVICE_RELOAD, blocking=True) + await hass.async_block_till_done() + + assert "Modbus reloading" in caplog.text + assert "connect failed, retry in pymodbus" in caplog.text