Use @pytest.mark.usefixtures() in Plugwise test code (#181095)

This commit is contained in:
Bouwe Westerdijk
2026-09-02 18:05:54 +01:00
committed by GitHub
parent a6e86ab910
commit 0c5bac0896
9 changed files with 38 additions and 39 deletions
@@ -1,7 +1,5 @@
"""Tests for the Plugwise binary_sensor integration."""
from unittest.mock import MagicMock
import pytest
from syrupy.assertion import SnapshotAssertion
@@ -14,11 +12,11 @@ from homeassistant.helpers.entity_component import async_update_entity
from tests.common import MockConfigEntry, snapshot_platform
@pytest.mark.usefixtures("mock_smile_adam")
@pytest.mark.parametrize("platforms", [(BINARY_SENSOR_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_adam_binary_sensor_snapshot(
hass: HomeAssistant,
mock_smile_adam: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
@@ -27,13 +25,13 @@ async def test_adam_binary_sensor_snapshot(
await snapshot_platform(hass, entity_registry, snapshot, setup_platform.entry_id)
@pytest.mark.usefixtures("mock_smile_anna")
@pytest.mark.parametrize("chosen_env", ["anna_heatpump_heating"], indirect=True)
@pytest.mark.parametrize("cooling_present", [True], indirect=True)
@pytest.mark.parametrize("platforms", [(BINARY_SENSOR_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_anna_binary_sensor_snapshot(
hass: HomeAssistant,
mock_smile_anna: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
@@ -42,10 +40,11 @@ async def test_anna_binary_sensor_snapshot(
await snapshot_platform(hass, entity_registry, snapshot, setup_platform.entry_id)
@pytest.mark.usefixtures("mock_smile_anna")
@pytest.mark.parametrize("chosen_env", ["anna_heatpump_heating"], indirect=True)
@pytest.mark.parametrize("cooling_present", [True], indirect=True)
async def test_anna_climate_binary_sensor_change(
hass: HomeAssistant, mock_smile_anna: MagicMock, init_integration: MockConfigEntry
hass: HomeAssistant, init_integration: MockConfigEntry
) -> None:
"""Test change of climate related binary_sensor entities."""
hass.states.async_set("binary_sensor.opentherm_dhw_state", STATE_ON, {})
@@ -61,6 +60,7 @@ async def test_anna_climate_binary_sensor_change(
assert state.state == STATE_OFF
@pytest.mark.usefixtures("mock_smile_p1")
@pytest.mark.parametrize("chosen_env", ["p1v4_442_triple"], indirect=True)
@pytest.mark.parametrize(
"gateway_id", ["03e65b16e4b247a29ae0d75a78cb492e"], indirect=True
@@ -69,7 +69,6 @@ async def test_anna_climate_binary_sensor_change(
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_p1_v4_binary_sensor_snapshot(
hass: HomeAssistant,
mock_smile_p1: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
+1 -1
View File
@@ -13,11 +13,11 @@ from homeassistant.helpers import entity_registry as er
from tests.common import MockConfigEntry, snapshot_platform
@pytest.mark.usefixtures("mock_smile_adam")
@pytest.mark.parametrize("platforms", [(BUTTON_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_adam_button_snapshot(
hass: HomeAssistant,
mock_smile_adam: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
+5 -5
View File
@@ -48,11 +48,11 @@ HA_PLUGWISE_SMILE_ASYNC_UPDATE = (
)
@pytest.mark.usefixtures("mock_smile_adam")
@pytest.mark.parametrize("platforms", [(CLIMATE_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_adam_climate_snapshot(
hass: HomeAssistant,
mock_smile_adam: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
@@ -267,13 +267,13 @@ async def test_adam_restore_state_climate(
assert mock_smile_adam_heat_cool.set_schedule_state.call_count == 2
@pytest.mark.usefixtures("mock_smile_adam_heat_cool")
@pytest.mark.parametrize("chosen_env", ["m_adam_heating"], indirect=True)
@pytest.mark.parametrize("cooling_present", [False], indirect=True)
@pytest.mark.parametrize("platforms", [(CLIMATE_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_adam_2_climate_snapshot(
hass: HomeAssistant,
mock_smile_adam_heat_cool: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
@@ -591,13 +591,13 @@ async def test_adam_climate_off_mode_change(
assert mock_smile_adam_jip.set_regulation_mode.call_count == 2
@pytest.mark.usefixtures("mock_smile_anna")
@pytest.mark.parametrize("chosen_env", ["anna_heatpump_heating"], indirect=True)
@pytest.mark.parametrize("cooling_present", [True], indirect=True)
@pytest.mark.parametrize("platforms", [(CLIMATE_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_anna_climate_snapshot(
hass: HomeAssistant,
mock_smile_anna: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
@@ -699,13 +699,13 @@ async def test_anna_climate_entity_climate_changes(
assert state.attributes[ATTR_HVAC_MODES] == [HVACMode.HEAT_COOL]
@pytest.mark.usefixtures("mock_smile_anna")
@pytest.mark.parametrize("chosen_env", ["m_anna_heatpump_cooling"], indirect=True)
@pytest.mark.parametrize("cooling_present", [True], indirect=True)
@pytest.mark.parametrize("platforms", [(CLIMATE_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_anna_2_climate_snapshot(
hass: HomeAssistant,
mock_smile_anna: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
@@ -746,9 +746,9 @@ async def test_tom_without_temperature_measurement(
assert state.attributes[ATTR_CURRENT_TEMPERATURE] is None
@pytest.mark.usefixtures("mock_smile_legacy_anna")
async def test_legacy_anna_no_schedule(
hass: HomeAssistant,
mock_smile_legacy_anna: MagicMock,
init_integration: MockConfigEntry,
) -> None:
"""Test failing to set a schedule with no schedule defined."""
+2 -2
View File
@@ -167,6 +167,7 @@ async def test_device_via_device_links(
assert child_device.via_device_id == gateway_device.id
@pytest.mark.usefixtures("mock_smile_anna")
@pytest.mark.parametrize("chosen_env", ["anna_heatpump_heating"], indirect=True)
@pytest.mark.parametrize("cooling_present", [True], indirect=True)
@pytest.mark.parametrize(
@@ -189,7 +190,6 @@ async def test_migrate_unique_id_temperature(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_config_entry: MockConfigEntry,
mock_smile_anna: MagicMock,
entitydata: dict,
old_unique_id: str,
new_unique_id: str,
@@ -210,6 +210,7 @@ async def test_migrate_unique_id_temperature(
assert entity_migrated.unique_id == new_unique_id
@pytest.mark.usefixtures("mock_smile_adam")
@pytest.mark.parametrize(
("entitydata", "old_unique_id", "new_unique_id"),
[
@@ -241,7 +242,6 @@ async def test_migrate_unique_id_relay(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_config_entry: MockConfigEntry,
mock_smile_adam: MagicMock,
entitydata: dict,
old_unique_id: str,
new_unique_id: str,
+4 -3
View File
@@ -18,11 +18,11 @@ from homeassistant.helpers import entity_registry as er
from tests.common import MockConfigEntry, snapshot_platform
@pytest.mark.usefixtures("mock_smile_adam")
@pytest.mark.parametrize("platforms", [(NUMBER_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_adam_number_entities(
hass: HomeAssistant,
mock_smile_adam: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
@@ -51,8 +51,9 @@ async def test_adam_temperature_offset_change(
)
@pytest.mark.usefixtures("mock_smile_adam")
async def test_adam_temperature_offset_out_of_bounds_change(
hass: HomeAssistant, mock_smile_adam: MagicMock, init_integration: MockConfigEntry
hass: HomeAssistant, init_integration: MockConfigEntry
) -> None:
"""Test changing an Adam temperature_offset number beyond limits."""
with pytest.raises(ServiceValidationError, match="valid range"):
@@ -95,13 +96,13 @@ async def test_adam_dhw_setpoint_change(
)
@pytest.mark.usefixtures("mock_smile_anna")
@pytest.mark.parametrize("chosen_env", ["anna_heatpump_heating"], indirect=True)
@pytest.mark.parametrize("cooling_present", [True], indirect=True)
@pytest.mark.parametrize("platforms", [(NUMBER_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_anna_number_entities(
hass: HomeAssistant,
mock_smile_anna: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
+6 -5
View File
@@ -25,11 +25,11 @@ from homeassistant.helpers import entity_registry as er
from tests.common import MockConfigEntry, snapshot_platform
@pytest.mark.usefixtures("mock_smile_adam")
@pytest.mark.parametrize("platforms", [(SELECT_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_adam_select_entities(
hass: HomeAssistant,
mock_smile_adam: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
@@ -61,13 +61,13 @@ async def test_adam_change_select_entity(
)
@pytest.mark.usefixtures("mock_smile_adam_heat_cool")
@pytest.mark.parametrize("chosen_env", ["m_adam_cooling"], indirect=True)
@pytest.mark.parametrize("cooling_present", [True], indirect=True)
@pytest.mark.parametrize("platforms", [(SELECT_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_adam_2_select_entities(
hass: HomeAssistant,
mock_smile_adam_heat_cool: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
@@ -148,9 +148,9 @@ async def test_adam_select_zone_profile(
)
@pytest.mark.usefixtures("mock_smile_legacy_anna")
async def test_legacy_anna_select_entities(
hass: HomeAssistant,
mock_smile_legacy_anna: MagicMock,
init_integration: MockConfigEntry,
) -> None:
"""Test that "off" is the selected option for legacy Anna without schedule."""
@@ -158,10 +158,11 @@ async def test_legacy_anna_select_entities(
assert state.state == "off"
@pytest.mark.usefixtures("mock_smile_anna")
@pytest.mark.parametrize("chosen_env", ["anna_heatpump_heating"], indirect=True)
@pytest.mark.parametrize("cooling_present", [True], indirect=True)
async def test_anna_select_unavailable_schedule_mode(
hass: HomeAssistant, mock_smile_anna: MagicMock, init_integration: MockConfigEntry
hass: HomeAssistant, init_integration: MockConfigEntry
) -> None:
"""Fail-test an Anna thermostat_schedule select option."""
@@ -177,13 +178,13 @@ async def test_anna_select_unavailable_schedule_mode(
)
@pytest.mark.usefixtures("mock_smile_anna")
@pytest.mark.parametrize("chosen_env", ["anna_loria_cooling_active"], indirect=True)
@pytest.mark.parametrize("cooling_present", [True], indirect=True)
@pytest.mark.parametrize("platforms", [(SELECT_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_anna_entities_with_dhw_mode_select(
hass: HomeAssistant,
mock_smile_anna: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
+9 -11
View File
@@ -1,7 +1,5 @@
"""Tests for the Plugwise Sensor integration."""
from unittest.mock import MagicMock
import pytest
from syrupy.assertion import SnapshotAssertion
@@ -13,13 +11,13 @@ from homeassistant.helpers import entity_registry as er
from tests.common import MockConfigEntry, snapshot_platform
@pytest.mark.usefixtures("mock_smile_adam_heat_cool")
@pytest.mark.parametrize("chosen_env", ["m_adam_heating"], indirect=True)
@pytest.mark.parametrize("cooling_present", [False], indirect=True)
@pytest.mark.parametrize("platforms", [(SENSOR_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_adam_sensor_snapshot(
hass: HomeAssistant,
mock_smile_adam_heat_cool: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
@@ -28,9 +26,9 @@ async def test_adam_sensor_snapshot(
await snapshot_platform(hass, entity_registry, snapshot, setup_platform.entry_id)
@pytest.mark.usefixtures("mock_smile_adam_jip")
async def test_adam_climate_sensor_humidity(
hass: HomeAssistant,
mock_smile_adam_jip: MagicMock,
init_integration: MockConfigEntry,
) -> None:
"""Test creation of climate related humidity sensor entity."""
@@ -39,10 +37,10 @@ async def test_adam_climate_sensor_humidity(
assert float(state.state) == 56.2
@pytest.mark.usefixtures("mock_smile_adam_jip")
async def test_unique_id_migration_humidity(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_smile_adam_jip: MagicMock,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test unique ID migration of -relative_humidity to -humidity."""
@@ -82,13 +80,13 @@ async def test_unique_id_migration_humidity(
assert entity_entry.unique_id == "f61f1a2535f54f52ad006a3d18e459ca-battery"
@pytest.mark.usefixtures("mock_smile_anna")
@pytest.mark.parametrize("chosen_env", ["anna_heatpump_heating"], indirect=True)
@pytest.mark.parametrize("cooling_present", [True], indirect=True)
@pytest.mark.parametrize("platforms", [(SENSOR_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_anna_sensor_snapshot(
hass: HomeAssistant,
mock_smile_anna: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
@@ -97,11 +95,11 @@ async def test_anna_sensor_snapshot(
await snapshot_platform(hass, entity_registry, snapshot, setup_platform.entry_id)
@pytest.mark.usefixtures("mock_smile_anna_p1")
@pytest.mark.parametrize("platforms", [(SENSOR_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_anna_p1_sensor_snapshot(
hass: HomeAssistant,
mock_smile_anna_p1: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
@@ -110,6 +108,7 @@ async def test_anna_p1_sensor_snapshot(
await snapshot_platform(hass, entity_registry, snapshot, setup_platform.entry_id)
@pytest.mark.usefixtures("mock_smile_p1")
@pytest.mark.parametrize("chosen_env", ["p1v4_442_single"], indirect=True)
@pytest.mark.parametrize(
"gateway_id", ["a455b61e52394b2db5081ce025a430f3"], indirect=True
@@ -118,7 +117,6 @@ async def test_anna_p1_sensor_snapshot(
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_p1_dsmr_sensor_snapshot(
hass: HomeAssistant,
mock_smile_p1: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
@@ -127,6 +125,7 @@ async def test_p1_dsmr_sensor_snapshot(
await snapshot_platform(hass, entity_registry, snapshot, setup_platform.entry_id)
@pytest.mark.usefixtures("mock_smile_p1")
@pytest.mark.parametrize("chosen_env", ["p1v4_442_triple"], indirect=True)
@pytest.mark.parametrize(
"gateway_id", ["03e65b16e4b247a29ae0d75a78cb492e"], indirect=True
@@ -135,7 +134,6 @@ async def test_p1_dsmr_sensor_snapshot(
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_p1_3ph_dsmr_sensor_snapshot(
hass: HomeAssistant,
mock_smile_p1: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
@@ -144,6 +142,7 @@ async def test_p1_3ph_dsmr_sensor_snapshot(
await snapshot_platform(hass, entity_registry, snapshot, setup_platform.entry_id)
@pytest.mark.usefixtures("mock_smile_p1")
@pytest.mark.parametrize("chosen_env", ["p1v4_442_triple"], indirect=True)
@pytest.mark.parametrize(
"gateway_id", ["03e65b16e4b247a29ae0d75a78cb492e"], indirect=True
@@ -151,7 +150,6 @@ async def test_p1_3ph_dsmr_sensor_snapshot(
async def test_p1_3ph_dsmr_sensor_disabled_entities(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_smile_p1: MagicMock,
init_integration: MockConfigEntry,
) -> None:
"""Test disabled power related sensor entities intent."""
@@ -170,11 +168,11 @@ async def test_p1_3ph_dsmr_sensor_disabled_entities(
assert float(state.state) == 233.2
@pytest.mark.usefixtures("mock_stretch")
@pytest.mark.parametrize("platforms", [(SENSOR_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_stretch_sensor_snapshot(
hass: HomeAssistant,
mock_stretch: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
+3 -3
View File
@@ -23,11 +23,11 @@ from homeassistant.helpers import entity_registry as er
from tests.common import MockConfigEntry, snapshot_platform
@pytest.mark.usefixtures("mock_smile_adam")
@pytest.mark.parametrize("platforms", [(SWITCH_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_adam_switch_snapshot(
hass: HomeAssistant,
mock_smile_adam: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
@@ -110,11 +110,11 @@ async def test_adam_climate_switch_negative_testing(
)
@pytest.mark.usefixtures("mock_stretch")
@pytest.mark.parametrize("platforms", [(SWITCH_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_stretch_switch_snapshot(
hass: HomeAssistant,
mock_stretch: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
@@ -161,10 +161,10 @@ async def test_stretch_switch_changes(
)
@pytest.mark.usefixtures("mock_smile_adam")
async def test_unique_id_migration_plug_relay(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
mock_smile_adam: MagicMock,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test unique ID migration of -plugs to -relay."""
@@ -27,11 +27,11 @@ HA_PLUGWISE_SMILE_ASYNC_UPDATE = (
)
@pytest.mark.usefixtures("mock_smile_adam_jip")
@pytest.mark.parametrize("platforms", [(WATER_HEATER_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_adam_water_heater_snapshot(
hass: HomeAssistant,
mock_smile_adam_jip: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
@@ -87,13 +87,13 @@ async def test_adam_water_heater_setpoint_change(
assert mock_smile_adam_jip.set_number.call_count == 1
@pytest.mark.usefixtures("mock_smile_anna")
@pytest.mark.parametrize("chosen_env", ["anna_loria_cooling_active"], indirect=True)
@pytest.mark.parametrize("cooling_present", [False], indirect=True)
@pytest.mark.parametrize("platforms", [(WATER_HEATER_DOMAIN,)])
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_anna_water_heater_snapshot(
hass: HomeAssistant,
mock_smile_anna: MagicMock,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
setup_platform: MockConfigEntry,
@@ -164,9 +164,9 @@ async def test_adam_water_heater_active_state(
assert state.state == STATE_GAS
@pytest.mark.usefixtures("mock_smile_adam_jip")
async def test_adam_water_heater_setpoint_error_uses_configured_unit(
hass: HomeAssistant,
mock_smile_adam_jip: MagicMock,
init_integration: MockConfigEntry,
) -> None:
"""Test out-of-range setpoint errors use the configured temperature unit."""