diff --git a/tests/components/mqtt/test_common.py b/tests/components/mqtt/test_common.py index 659d69c2f91..e706bc47418 100644 --- a/tests/components/mqtt/test_common.py +++ b/tests/components/mqtt/test_common.py @@ -2,7 +2,6 @@ import copy from datetime import datetime import json -from unittest import mock from homeassistant.components import mqtt from homeassistant.components.mqtt import debug_info @@ -11,7 +10,7 @@ from homeassistant.const import ATTR_ASSUMED_STATE, STATE_UNAVAILABLE from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.setup import async_setup_component -from tests.async_mock import ANY +from tests.async_mock import ANY, patch from tests.common import async_fire_mqtt_message, mock_registry DEFAULT_CONFIG_DEVICE_INFO_ID = { @@ -834,7 +833,7 @@ async def help_test_entity_debug_info_max_messages(hass, mqtt_mock, domain, conf ] start_dt = datetime(2019, 1, 1, 0, 0, 0) - with mock.patch("homeassistant.util.dt.utcnow") as dt_utcnow: + with patch("homeassistant.util.dt.utcnow") as dt_utcnow: dt_utcnow.return_value = start_dt for i in range(0, debug_info.STORED_MESSAGES + 1): async_fire_mqtt_message(hass, "test-topic", f"{i}") @@ -896,7 +895,7 @@ async def help_test_entity_debug_info_message( ] start_dt = datetime(2019, 1, 1, 0, 0, 0) - with mock.patch("homeassistant.util.dt.utcnow") as dt_utcnow: + with patch("homeassistant.util.dt.utcnow") as dt_utcnow: dt_utcnow.return_value = start_dt async_fire_mqtt_message(hass, topic, payload) diff --git a/tests/components/mqtt/test_subscription.py b/tests/components/mqtt/test_subscription.py index 05f14107384..19797f28c3f 100644 --- a/tests/components/mqtt/test_subscription.py +++ b/tests/components/mqtt/test_subscription.py @@ -1,12 +1,11 @@ """The tests for the MQTT subscription component.""" -from unittest import mock - from homeassistant.components.mqtt.subscription import ( async_subscribe_topics, async_unsubscribe_topics, ) from homeassistant.core import callback +from tests.async_mock import ANY from tests.common import async_fire_mqtt_message @@ -131,9 +130,7 @@ async def test_qos_encoding_default(hass, mqtt_mock, caplog): sub_state, {"test_topic1": {"topic": "test-topic1", "msg_callback": msg_callback}}, ) - mqtt_mock.async_subscribe.assert_called_once_with( - "test-topic1", mock.ANY, 0, "utf-8" - ) + mqtt_mock.async_subscribe.assert_called_once_with("test-topic1", ANY, 0, "utf-8") async def test_qos_encoding_custom(hass, mqtt_mock, caplog): @@ -157,9 +154,7 @@ async def test_qos_encoding_custom(hass, mqtt_mock, caplog): } }, ) - mqtt_mock.async_subscribe.assert_called_once_with( - "test-topic1", mock.ANY, 1, "utf-16" - ) + mqtt_mock.async_subscribe.assert_called_once_with("test-topic1", ANY, 1, "utf-16") async def test_no_change(hass, mqtt_mock, caplog): diff --git a/tests/components/mqtt/test_trigger.py b/tests/components/mqtt/test_trigger.py index 13e96c69adc..b35082ef2c6 100644 --- a/tests/components/mqtt/test_trigger.py +++ b/tests/components/mqtt/test_trigger.py @@ -1,12 +1,11 @@ """The tests for the MQTT automation.""" -from unittest import mock - import pytest import homeassistant.components.automation as automation from homeassistant.const import ATTR_ENTITY_ID, ENTITY_MATCH_ALL, SERVICE_TURN_OFF from homeassistant.setup import async_setup_component +from tests.async_mock import ANY from tests.common import async_fire_mqtt_message, async_mock_service, mock_component @@ -115,9 +114,7 @@ async def test_encoding_default(hass, calls, mqtt_mock): }, ) - mqtt_mock.async_subscribe.assert_called_once_with( - "test-topic", mock.ANY, 0, "utf-8" - ) + mqtt_mock.async_subscribe.assert_called_once_with("test-topic", ANY, 0, "utf-8") async def test_encoding_custom(hass, calls, mqtt_mock): @@ -133,4 +130,4 @@ async def test_encoding_custom(hass, calls, mqtt_mock): }, ) - mqtt_mock.async_subscribe.assert_called_once_with("test-topic", mock.ANY, 0, None) + mqtt_mock.async_subscribe.assert_called_once_with("test-topic", ANY, 0, None)