diff --git a/tests/components/device_tracker/test_mqtt.py b/tests/components/mqtt/test_device_tracker.py similarity index 82% rename from tests/components/device_tracker/test_mqtt.py rename to tests/components/mqtt/test_device_tracker.py index 3e584aa541cf..665be9b34778 100644 --- a/tests/components/device_tracker/test_mqtt.py +++ b/tests/components/mqtt/test_device_tracker.py @@ -1,27 +1,18 @@ """The tests for the MQTT device tracker platform.""" -import logging -import os from asynctest import patch import pytest -from homeassistant.setup import async_setup_component from homeassistant.components import device_tracker from homeassistant.const import CONF_PLATFORM +from homeassistant.setup import async_setup_component -from tests.common import ( - async_mock_mqtt_component, async_fire_mqtt_message) - -_LOGGER = logging.getLogger(__name__) +from tests.common import async_fire_mqtt_message @pytest.fixture(autouse=True) -def setup_comp(hass): - """Initialize components.""" - hass.loop.run_until_complete(async_mock_mqtt_component(hass)) - yaml_devices = hass.config.path(device_tracker.YAML_DEVICES) - yield - if os.path.isfile(yaml_devices): - os.remove(yaml_devices) +def setup_comp(hass, mqtt_mock): + """Set up mqtt component.""" + pass async def test_ensure_device_tracker_platform_validation(hass): @@ -45,7 +36,7 @@ async def mock_setup_scanner(hass, config, see, discovery_info=None): assert mock_sp.call_count == 1 -async def test_new_message(hass): +async def test_new_message(hass, mock_device_tracker_conf): """Test new message.""" dev_id = 'paulus' entity_id = device_tracker.ENTITY_ID_FORMAT.format(dev_id) @@ -61,10 +52,10 @@ async def test_new_message(hass): }) async_fire_mqtt_message(hass, topic, location) await hass.async_block_till_done() - assert location == hass.states.get(entity_id).state + assert hass.states.get(entity_id).state == location -async def test_single_level_wildcard_topic(hass): +async def test_single_level_wildcard_topic(hass, mock_device_tracker_conf): """Test single level wildcard topic.""" dev_id = 'paulus' entity_id = device_tracker.ENTITY_ID_FORMAT.format(dev_id) @@ -81,10 +72,10 @@ async def test_single_level_wildcard_topic(hass): }) async_fire_mqtt_message(hass, topic, location) await hass.async_block_till_done() - assert location == hass.states.get(entity_id).state + assert hass.states.get(entity_id).state == location -async def test_multi_level_wildcard_topic(hass): +async def test_multi_level_wildcard_topic(hass, mock_device_tracker_conf): """Test multi level wildcard topic.""" dev_id = 'paulus' entity_id = device_tracker.ENTITY_ID_FORMAT.format(dev_id) @@ -101,10 +92,11 @@ async def test_multi_level_wildcard_topic(hass): }) async_fire_mqtt_message(hass, topic, location) await hass.async_block_till_done() - assert location == hass.states.get(entity_id).state + assert hass.states.get(entity_id).state == location -async def test_single_level_wildcard_topic_not_matching(hass): +async def test_single_level_wildcard_topic_not_matching( + hass, mock_device_tracker_conf): """Test not matching single level wildcard topic.""" dev_id = 'paulus' entity_id = device_tracker.ENTITY_ID_FORMAT.format(dev_id) @@ -124,7 +116,8 @@ async def test_single_level_wildcard_topic_not_matching(hass): assert hass.states.get(entity_id) is None -async def test_multi_level_wildcard_topic_not_matching(hass): +async def test_multi_level_wildcard_topic_not_matching( + hass, mock_device_tracker_conf): """Test not matching multi level wildcard topic.""" dev_id = 'paulus' entity_id = device_tracker.ENTITY_ID_FORMAT.format(dev_id)