Speed up zha tests (#73627)

This commit is contained in:
J. Nick Koston 2022-06-17 11:41:10 -05:00 committed by GitHub
parent bf15df75dd
commit 4bc5d7bfed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 347 additions and 4 deletions

View File

@ -22,6 +22,21 @@ from .common import async_enable_traffic, find_entity_id
from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE
@pytest.fixture(autouse=True)
def alarm_control_panel_platform_only():
"""Only setup the alarm_control_panel and required base platforms to speed up tests."""
with patch(
"homeassistant.components.zha.PLATFORMS",
(
Platform.ALARM_CONTROL_PANEL,
Platform.DEVICE_TRACKER,
Platform.NUMBER,
Platform.SELECT,
),
):
yield
@pytest.fixture @pytest.fixture
def zigpy_device(zigpy_device_mock): def zigpy_device(zigpy_device_mock):
"""Device tracker zigpy device.""" """Device tracker zigpy device."""

View File

@ -37,7 +37,7 @@ from homeassistant.components.zha.core.const import (
GROUP_IDS, GROUP_IDS,
GROUP_NAME, GROUP_NAME,
) )
from homeassistant.const import ATTR_NAME from homeassistant.const import ATTR_NAME, Platform
from homeassistant.core import Context from homeassistant.core import Context
from .conftest import ( from .conftest import (
@ -53,6 +53,20 @@ IEEE_SWITCH_DEVICE = "01:2d:6f:00:0a:90:69:e7"
IEEE_GROUPABLE_DEVICE = "01:2d:6f:00:0a:90:69:e8" IEEE_GROUPABLE_DEVICE = "01:2d:6f:00:0a:90:69:e8"
@pytest.fixture(autouse=True)
def required_platform_only():
"""Only setup the required and required base platforms to speed up tests."""
with patch(
"homeassistant.components.zha.PLATFORMS",
(
Platform.SELECT,
Platform.SENSOR,
Platform.SWITCH,
),
):
yield
@pytest.fixture @pytest.fixture
async def device_switch(hass, zigpy_device_mock, zha_device_joined): async def device_switch(hass, zigpy_device_mock, zha_device_joined):
"""Test zha switch platform.""" """Test zha switch platform."""

View File

@ -1,4 +1,6 @@
"""Test zha binary sensor.""" """Test zha binary sensor."""
from unittest.mock import patch
import pytest import pytest
import zigpy.profiles.zha import zigpy.profiles.zha
import zigpy.zcl.clusters.measurement as measurement import zigpy.zcl.clusters.measurement as measurement
@ -34,6 +36,21 @@ DEVICE_OCCUPANCY = {
} }
@pytest.fixture(autouse=True)
def binary_sensor_platform_only():
"""Only setup the binary_sensor and required base platforms to speed up tests."""
with patch(
"homeassistant.components.zha.PLATFORMS",
(
Platform.BINARY_SENSOR,
Platform.DEVICE_TRACKER,
Platform.NUMBER,
Platform.SELECT,
),
):
yield
async def async_test_binary_sensor_on_off(hass, cluster, entity_id): async def async_test_binary_sensor_on_off(hass, cluster, entity_id):
"""Test getting on and off messages for binary sensors.""" """Test getting on and off messages for binary sensors."""
# binary sensor on # binary sensor on

View File

@ -28,6 +28,7 @@ from homeassistant.const import (
ENTITY_CATEGORY_CONFIG, ENTITY_CATEGORY_CONFIG,
ENTITY_CATEGORY_DIAGNOSTIC, ENTITY_CATEGORY_DIAGNOSTIC,
STATE_UNKNOWN, STATE_UNKNOWN,
Platform,
) )
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
@ -37,6 +38,23 @@ from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_TYPE
from tests.common import mock_coro from tests.common import mock_coro
@pytest.fixture(autouse=True)
def button_platform_only():
"""Only setup the button and required base platforms to speed up tests."""
with patch(
"homeassistant.components.zha.PLATFORMS",
(
Platform.BINARY_SENSOR,
Platform.BUTTON,
Platform.DEVICE_TRACKER,
Platform.NUMBER,
Platform.SELECT,
Platform.SENSOR,
),
):
yield
@pytest.fixture @pytest.fixture
async def contact_sensor(hass, zigpy_device_mock, zha_device_joined_restored): async def contact_sensor(hass, zigpy_device_mock, zha_device_joined_restored):
"""Contact sensor fixture.""" """Contact sensor fixture."""

View File

@ -20,6 +20,13 @@ from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_TYPE
from tests.common import async_capture_events from tests.common import async_capture_events
@pytest.fixture(autouse=True)
def disable_platform_only():
"""Disable platforms to speed up tests."""
with patch("homeassistant.components.zha.PLATFORMS", []):
yield
@pytest.fixture @pytest.fixture
def ieee(): def ieee():
"""IEEE fixture.""" """IEEE fixture."""

View File

@ -171,6 +171,24 @@ ZCL_ATTR_PLUG = {
} }
@pytest.fixture(autouse=True)
def climate_platform_only():
"""Only setup the climate and required base platforms to speed up tests."""
with patch(
"homeassistant.components.zha.PLATFORMS",
(
Platform.BUTTON,
Platform.CLIMATE,
Platform.BINARY_SENSOR,
Platform.NUMBER,
Platform.SELECT,
Platform.SENSOR,
Platform.SWITCH,
),
):
yield
@pytest.fixture @pytest.fixture
def device_climate_mock(hass, zigpy_device_mock, zha_device_joined): def device_climate_mock(hass, zigpy_device_mock, zha_device_joined):
"""Test regular thermostat device.""" """Test regular thermostat device."""

View File

@ -34,6 +34,13 @@ from homeassistant.data_entry_flow import (
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@pytest.fixture(autouse=True)
def disable_platform_only():
"""Disable platforms to speed up tests."""
with patch("homeassistant.components.zha.PLATFORMS", []):
yield
def com_port(): def com_port():
"""Mock of a serial port.""" """Mock of a serial port."""
port = serial.tools.list_ports_common.ListPortInfo("/dev/ttyUSB1234") port = serial.tools.list_ports_common.ListPortInfo("/dev/ttyUSB1234")

View File

@ -39,6 +39,21 @@ from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE
from tests.common import async_capture_events, mock_coro, mock_restore_cache from tests.common import async_capture_events, mock_coro, mock_restore_cache
@pytest.fixture(autouse=True)
def cover_platform_only():
"""Only setup the cover and required base platforms to speed up tests."""
with patch(
"homeassistant.components.zha.PLATFORMS",
(
Platform.COVER,
Platform.DEVICE_TRACKER,
Platform.NUMBER,
Platform.SELECT,
),
):
yield
@pytest.fixture @pytest.fixture
def zigpy_cover_device(zigpy_device_mock): def zigpy_cover_device(zigpy_device_mock):
"""Zigpy cover device.""" """Zigpy cover device."""

View File

@ -12,7 +12,7 @@ from homeassistant.components.zha.core.const import (
CONF_DEFAULT_CONSIDER_UNAVAILABLE_BATTERY, CONF_DEFAULT_CONSIDER_UNAVAILABLE_BATTERY,
CONF_DEFAULT_CONSIDER_UNAVAILABLE_MAINS, CONF_DEFAULT_CONSIDER_UNAVAILABLE_MAINS,
) )
from homeassistant.const import STATE_OFF, STATE_UNAVAILABLE from homeassistant.const import STATE_OFF, STATE_UNAVAILABLE, Platform
import homeassistant.helpers.device_registry as dr import homeassistant.helpers.device_registry as dr
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
@ -22,6 +22,22 @@ from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_TYPE
from tests.common import async_fire_time_changed from tests.common import async_fire_time_changed
@pytest.fixture(autouse=True)
def required_platforms_only():
"""Only setup the required platform and required base platforms to speed up tests."""
with patch(
"homeassistant.components.zha.PLATFORMS",
(
Platform.DEVICE_TRACKER,
Platform.SENSOR,
Platform.SELECT,
Platform.SWITCH,
Platform.BINARY_SENSOR,
),
):
yield
@pytest.fixture @pytest.fixture
def zigpy_device(zigpy_device_mock): def zigpy_device(zigpy_device_mock):
"""Device tracker zigpy device.""" """Device tracker zigpy device."""

View File

@ -24,6 +24,23 @@ COMMAND = "command"
COMMAND_SINGLE = "single" COMMAND_SINGLE = "single"
@pytest.fixture(autouse=True)
def required_platforms_only():
"""Only setup the required platforms and required base platforms to speed up tests."""
with patch(
"homeassistant.components.zha.PLATFORMS",
(
Platform.BINARY_SENSOR,
Platform.DEVICE_TRACKER,
Platform.NUMBER,
Platform.SELECT,
Platform.SENSOR,
Platform.SIREN,
),
):
yield
@pytest.fixture @pytest.fixture
async def device_ias(hass, zigpy_device_mock, zha_device_joined_restored): async def device_ias(hass, zigpy_device_mock, zha_device_joined_restored):
"""IAS device fixture.""" """IAS device fixture."""

View File

@ -1,6 +1,7 @@
"""Test ZHA Device Tracker.""" """Test ZHA Device Tracker."""
from datetime import timedelta from datetime import timedelta
import time import time
from unittest.mock import patch
import pytest import pytest
import zigpy.profiles.zha import zigpy.profiles.zha
@ -24,6 +25,23 @@ from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE
from tests.common import async_fire_time_changed from tests.common import async_fire_time_changed
@pytest.fixture(autouse=True)
def device_tracker_platforms_only():
"""Only setup the device_tracker platforms and required base platforms to speed up tests."""
with patch(
"homeassistant.components.zha.PLATFORMS",
(
Platform.DEVICE_TRACKER,
Platform.BUTTON,
Platform.SELECT,
Platform.NUMBER,
Platform.BINARY_SENSOR,
Platform.SENSOR,
),
):
yield
@pytest.fixture @pytest.fixture
def zigpy_device_dt(zigpy_device_mock): def zigpy_device_dt(zigpy_device_mock):
"""Device tracker zigpy device.""" """Device tracker zigpy device."""

View File

@ -1,6 +1,7 @@
"""ZHA device automation trigger tests.""" """ZHA device automation trigger tests."""
from datetime import timedelta from datetime import timedelta
import time import time
from unittest.mock import patch
import pytest import pytest
import zigpy.profiles.zha import zigpy.profiles.zha
@ -8,6 +9,7 @@ import zigpy.zcl.clusters.general as general
import homeassistant.components.automation as automation import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.const import Platform
from homeassistant.helpers import device_registry as dr from homeassistant.helpers import device_registry as dr
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
@ -36,6 +38,13 @@ LONG_PRESS = "remote_button_long_press"
LONG_RELEASE = "remote_button_long_release" LONG_RELEASE = "remote_button_long_release"
@pytest.fixture(autouse=True)
def sensor_platforms_only():
"""Only setup the sensor platform and required base platforms to speed up tests."""
with patch("homeassistant.components.zha.PLATFORMS", (Platform.SENSOR,)):
yield
def _same_lists(list_a, list_b): def _same_lists(list_a, list_b):
if len(list_a) != len(list_b): if len(list_a) != len(list_b):
return False return False

View File

@ -1,6 +1,8 @@
"""Tests for the diagnostics data provided by the ESPHome integration.""" """Tests for the diagnostics data provided by the ESPHome integration."""
from unittest.mock import patch
import pytest import pytest
import zigpy.profiles.zha as zha import zigpy.profiles.zha as zha
import zigpy.zcl.clusters.security as security import zigpy.zcl.clusters.security as security
@ -8,6 +10,7 @@ import zigpy.zcl.clusters.security as security
from homeassistant.components.diagnostics.const import REDACTED from homeassistant.components.diagnostics.const import REDACTED
from homeassistant.components.zha.core.device import ZHADevice from homeassistant.components.zha.core.device import ZHADevice
from homeassistant.components.zha.diagnostics import KEYS_TO_REDACT from homeassistant.components.zha.diagnostics import KEYS_TO_REDACT
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import async_get from homeassistant.helpers.device_registry import async_get
@ -26,6 +29,15 @@ CONFIG_ENTRY_DIAGNOSTICS_KEYS = [
] ]
@pytest.fixture(autouse=True)
def required_platforms_only():
"""Only setup the required platform and required base platforms to speed up tests."""
with patch(
"homeassistant.components.zha.PLATFORMS", (Platform.ALARM_CONTROL_PANEL,)
):
yield
@pytest.fixture @pytest.fixture
def zigpy_device(zigpy_device_mock): def zigpy_device(zigpy_device_mock):
"""Device tracker zigpy device.""" """Device tracker zigpy device."""

View File

@ -51,6 +51,22 @@ IEEE_GROUPABLE_DEVICE = "01:2d:6f:00:0a:90:69:e8"
IEEE_GROUPABLE_DEVICE2 = "02:2d:6f:00:0a:90:69:e8" IEEE_GROUPABLE_DEVICE2 = "02:2d:6f:00:0a:90:69:e8"
@pytest.fixture(autouse=True)
def fan_platform_only():
"""Only setup the fan and required base platforms to speed up tests."""
with patch(
"homeassistant.components.zha.PLATFORMS",
(
Platform.FAN,
Platform.LIGHT,
Platform.DEVICE_TRACKER,
Platform.NUMBER,
Platform.SELECT,
),
):
yield
@pytest.fixture @pytest.fixture
def zigpy_device(zigpy_device_mock): def zigpy_device(zigpy_device_mock):
"""Device tracker zigpy device.""" """Device tracker zigpy device."""

View File

@ -35,6 +35,22 @@ def zigpy_dev_basic(zigpy_device_mock):
) )
@pytest.fixture(autouse=True)
def required_platform_only():
"""Only setup the required and required base platforms to speed up tests."""
with patch(
"homeassistant.components.zha.PLATFORMS",
(
Platform.SENSOR,
Platform.LIGHT,
Platform.DEVICE_TRACKER,
Platform.NUMBER,
Platform.SELECT,
),
):
yield
@pytest.fixture @pytest.fixture
async def zha_dev_basic(hass, zha_device_restored, zigpy_dev_basic): async def zha_dev_basic(hass, zha_device_restored, zigpy_dev_basic):
"""ZHA device with just a basic cluster.""" """ZHA device with just a basic cluster."""

View File

@ -20,6 +20,13 @@ DATA_RADIO_TYPE = "deconz"
DATA_PORT_PATH = "/dev/serial/by-id/FTDI_USB__-__Serial_Cable_12345678-if00-port0" DATA_PORT_PATH = "/dev/serial/by-id/FTDI_USB__-__Serial_Cable_12345678-if00-port0"
@pytest.fixture(autouse=True)
def disable_platform_only():
"""Disable platforms to speed up tests."""
with patch("homeassistant.components.zha.PLATFORMS", []):
yield
@pytest.fixture @pytest.fixture
def config_entry_v1(hass): def config_entry_v1(hass):
"""Config entry version 1 fixture.""" """Config entry version 1 fixture."""

View File

@ -80,6 +80,24 @@ LIGHT_COLOR = {
} }
@pytest.fixture(autouse=True)
def light_platform_only():
"""Only setup the light and required base platforms to speed up tests."""
with patch(
"homeassistant.components.zha.PLATFORMS",
(
Platform.BINARY_SENSOR,
Platform.DEVICE_TRACKER,
Platform.BUTTON,
Platform.LIGHT,
Platform.SENSOR,
Platform.NUMBER,
Platform.SELECT,
),
):
yield
@pytest.fixture @pytest.fixture
async def coordinator(hass, zigpy_device_mock, zha_device_joined): async def coordinator(hass, zigpy_device_mock, zha_device_joined):
"""Test zha light platform.""" """Test zha light platform."""

View File

@ -27,6 +27,20 @@ CLEAR_PIN_CODE = 7
SET_USER_STATUS = 9 SET_USER_STATUS = 9
@pytest.fixture(autouse=True)
def lock_platform_only():
"""Only setup the lock and required base platforms to speed up tests."""
with patch(
"homeassistant.components.zha.PLATFORMS",
(
Platform.DEVICE_TRACKER,
Platform.LOCK,
Platform.SENSOR,
),
):
yield
@pytest.fixture @pytest.fixture
async def lock(hass, zigpy_device_mock, zha_device_joined_restored): async def lock(hass, zigpy_device_mock, zha_device_joined_restored):
"""Lock cluster fixture.""" """Lock cluster fixture."""

View File

@ -1,11 +1,13 @@
"""ZHA logbook describe events tests.""" """ZHA logbook describe events tests."""
from unittest.mock import patch
import pytest import pytest
import zigpy.profiles.zha import zigpy.profiles.zha
import zigpy.zcl.clusters.general as general import zigpy.zcl.clusters.general as general
from homeassistant.components.zha.core.const import ZHA_EVENT from homeassistant.components.zha.core.const import ZHA_EVENT
from homeassistant.const import CONF_DEVICE_ID, CONF_UNIQUE_ID from homeassistant.const import CONF_DEVICE_ID, CONF_UNIQUE_ID, Platform
from homeassistant.helpers import device_registry as dr from homeassistant.helpers import device_registry as dr
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -29,6 +31,13 @@ UP = "up"
DOWN = "down" DOWN = "down"
@pytest.fixture(autouse=True)
def sensor_platform_only():
"""Only setup the sensor and required base platforms to speed up tests."""
with patch("homeassistant.components.zha.PLATFORMS", (Platform.SENSOR,)):
yield
@pytest.fixture @pytest.fixture
async def mock_devices(hass, zigpy_device_mock, zha_device_joined): async def mock_devices(hass, zigpy_device_mock, zha_device_joined):
"""IAS device fixture.""" """IAS device fixture."""

View File

@ -24,6 +24,23 @@ from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE
from tests.common import mock_coro from tests.common import mock_coro
@pytest.fixture(autouse=True)
def number_platform_only():
"""Only setup the number and required base platforms to speed up tests."""
with patch(
"homeassistant.components.zha.PLATFORMS",
(
Platform.BUTTON,
Platform.DEVICE_TRACKER,
Platform.LIGHT,
Platform.NUMBER,
Platform.SELECT,
Platform.SENSOR,
),
):
yield
@pytest.fixture @pytest.fixture
def zigpy_analog_output_device(zigpy_device_mock): def zigpy_analog_output_device(zigpy_device_mock):
"""Zigpy analog_output device.""" """Zigpy analog_output device."""

View File

@ -1,6 +1,6 @@
"""Test ZHA select entities.""" """Test ZHA select entities."""
from unittest.mock import call from unittest.mock import call, patch
import pytest import pytest
from zigpy.const import SIG_EP_PROFILE from zigpy.const import SIG_EP_PROFILE
@ -16,6 +16,24 @@ from .common import find_entity_id
from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_TYPE from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_TYPE
@pytest.fixture(autouse=True)
def select_select_only():
"""Only setup the select and required base platforms to speed up tests."""
with patch(
"homeassistant.components.zha.PLATFORMS",
(
Platform.BUTTON,
Platform.DEVICE_TRACKER,
Platform.SIREN,
Platform.LIGHT,
Platform.NUMBER,
Platform.SELECT,
Platform.SENSOR,
),
):
yield
@pytest.fixture @pytest.fixture
async def siren(hass, zigpy_device_mock, zha_device_joined_restored): async def siren(hass, zigpy_device_mock, zha_device_joined_restored):
"""Siren fixture.""" """Siren fixture."""

View File

@ -1,5 +1,6 @@
"""Test zha sensor.""" """Test zha sensor."""
import math import math
from unittest.mock import patch
import pytest import pytest
import zigpy.profiles.zha import zigpy.profiles.zha
@ -50,6 +51,19 @@ from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE
ENTITY_ID_PREFIX = "sensor.fakemanufacturer_fakemodel_e769900a_{}" ENTITY_ID_PREFIX = "sensor.fakemanufacturer_fakemodel_e769900a_{}"
@pytest.fixture(autouse=True)
def sensor_platform_only():
"""Only setup the sensor and required base platforms to speed up tests."""
with patch(
"homeassistant.components.zha.PLATFORMS",
(
Platform.DEVICE_TRACKER,
Platform.SENSOR,
),
):
yield
@pytest.fixture @pytest.fixture
async def elec_measurement_zigpy_dev(hass, zigpy_device_mock): async def elec_measurement_zigpy_dev(hass, zigpy_device_mock):
"""Electric Measurement zigpy device.""" """Electric Measurement zigpy device."""

View File

@ -28,6 +28,22 @@ from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_TYPE
from tests.common import async_fire_time_changed, mock_coro from tests.common import async_fire_time_changed, mock_coro
@pytest.fixture(autouse=True)
def siren_platform_only():
"""Only setup the siren and required base platforms to speed up tests."""
with patch(
"homeassistant.components.zha.PLATFORMS",
(
Platform.DEVICE_TRACKER,
Platform.NUMBER,
Platform.SENSOR,
Platform.SELECT,
Platform.SIREN,
),
):
yield
@pytest.fixture @pytest.fixture
async def siren(hass, zigpy_device_mock, zha_device_joined_restored): async def siren(hass, zigpy_device_mock, zha_device_joined_restored):
"""Siren fixture.""" """Siren fixture."""

View File

@ -41,6 +41,21 @@ IEEE_GROUPABLE_DEVICE = "01:2d:6f:00:0a:90:69:e8"
IEEE_GROUPABLE_DEVICE2 = "02:2d:6f:00:0a:90:69:e8" IEEE_GROUPABLE_DEVICE2 = "02:2d:6f:00:0a:90:69:e8"
@pytest.fixture(autouse=True)
def switch_platform_only():
"""Only setup the switch and required base platforms to speed up tests."""
with patch(
"homeassistant.components.zha.PLATFORMS",
(
Platform.DEVICE_TRACKER,
Platform.SENSOR,
Platform.SELECT,
Platform.SWITCH,
),
):
yield
@pytest.fixture @pytest.fixture
def zigpy_device(zigpy_device_mock): def zigpy_device(zigpy_device_mock):
"""Device tracker zigpy device.""" """Device tracker zigpy device."""