Skip to content

Commit

Permalink
Bring modbus back to 100% test coverage (home-assistant#85972)
Browse files Browse the repository at this point in the history
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
  • Loading branch information
janiversen and epenet authored Jan 16, 2023
1 parent bcef0d6 commit ee85a23
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/components/modbus/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ee85a23

Please sign in to comment.