From be0819b45602b00e98183d38f9b427f80e4f38a8 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Sat, 18 Sep 2021 09:40:58 +0200 Subject: [PATCH] Mock out network.util.async_get_source_ip in tests (#56339) --- tests/components/default_config/test_init.py | 2 +- tests/components/homekit/test_init.py | 2 +- tests/components/homekit/test_util.py | 2 +- tests/components/sonos/conftest.py | 6 ++++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/components/default_config/test_init.py b/tests/components/default_config/test_init.py index ec2d207a68b..1052eeeb164 100644 --- a/tests/components/default_config/test_init.py +++ b/tests/components/default_config/test_init.py @@ -29,6 +29,6 @@ def recorder_url_mock(): yield -async def test_setup(hass, mock_zeroconf): +async def test_setup(hass, mock_zeroconf, mock_get_source_ip): """Test setup.""" assert await async_setup_component(hass, "default_config", {"foo": "bar"}) diff --git a/tests/components/homekit/test_init.py b/tests/components/homekit/test_init.py index 6643ae9ae18..8652f8b032a 100644 --- a/tests/components/homekit/test_init.py +++ b/tests/components/homekit/test_init.py @@ -14,7 +14,7 @@ from homeassistant.setup import async_setup_component from tests.components.logbook.test_init import MockLazyEventPartialState -async def test_humanify_homekit_changed_event(hass, hk_driver): +async def test_humanify_homekit_changed_event(hass, hk_driver, mock_get_source_ip): """Test humanifying HomeKit changed event.""" hass.config.components.add("recorder") with patch("homeassistant.components.homekit.HomeKit"): diff --git a/tests/components/homekit/test_util.py b/tests/components/homekit/test_util.py index 2d4ac2171da..2c1deb3bd8e 100644 --- a/tests/components/homekit/test_util.py +++ b/tests/components/homekit/test_util.py @@ -238,7 +238,7 @@ def test_density_to_air_quality(): assert density_to_air_quality(300) == 5 -async def test_show_setup_msg(hass, hk_driver): +async def test_show_setup_msg(hass, hk_driver, mock_get_source_ip): """Test show setup message as persistence notification.""" pincode = b"123-45-678" diff --git a/tests/components/sonos/conftest.py b/tests/components/sonos/conftest.py index b1b3dd7be10..b81934e2593 100644 --- a/tests/components/sonos/conftest.py +++ b/tests/components/sonos/conftest.py @@ -202,3 +202,9 @@ def alarm_event_fixture(soco): } return SonosMockEvent(soco, soco.alarmClock, variables) + + +@pytest.fixture(autouse=True) +def mock_get_source_ip(mock_get_source_ip): + """Mock network util's async_get_source_ip in all sonos tests.""" + return mock_get_source_ip