diff --git a/tests/components/tuya/test_alarm_control_panel.py b/tests/components/tuya/test_alarm_control_panel.py index 4a60f0a2a74..a07065fd8e5 100644 --- a/tests/components/tuya/test_alarm_control_panel.py +++ b/tests/components/tuya/test_alarm_control_panel.py @@ -26,7 +26,15 @@ from . import initialize_entry from tests.common import MockConfigEntry, snapshot_platform -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.ALARM_CONTROL_PANEL]) +@pytest.fixture(autouse=True) +def platform_autouse(): + """Platform fixture.""" + with patch( + "homeassistant.components.tuya.PLATFORMS", [Platform.ALARM_CONTROL_PANEL] + ): + yield + + async def test_platform_setup_and_discovery( hass: HomeAssistant, mock_manager: Manager, @@ -41,7 +49,6 @@ async def test_platform_setup_and_discovery( await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.ALARM_CONTROL_PANEL]) @pytest.mark.parametrize( ("mock_device_code", "entity_id"), [ @@ -83,7 +90,6 @@ async def test_service( mock_manager.send_commands.assert_called_once_with(mock_device.id, [command]) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.ALARM_CONTROL_PANEL]) @pytest.mark.parametrize( ("mock_device_code", "entity_id"), [ diff --git a/tests/components/tuya/test_binary_sensor.py b/tests/components/tuya/test_binary_sensor.py index 1121b2ffbf6..3071507f35e 100644 --- a/tests/components/tuya/test_binary_sensor.py +++ b/tests/components/tuya/test_binary_sensor.py @@ -19,7 +19,13 @@ from . import MockDeviceListener, check_selective_state_update, initialize_entry from tests.common import MockConfigEntry, snapshot_platform -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.BINARY_SENSOR]) +@pytest.fixture(autouse=True) +def platform_autouse(): + """Platform fixture.""" + with patch("homeassistant.components.tuya.PLATFORMS", [Platform.BINARY_SENSOR]): + yield + + @pytest.mark.usefixtures("entity_registry_enabled_by_default") async def test_platform_setup_and_discovery( hass: HomeAssistant, @@ -55,7 +61,6 @@ async def test_platform_setup_and_discovery( ), ], ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.BINARY_SENSOR]) @pytest.mark.freeze_time("2024-01-01") async def test_selective_state_update( hass: HomeAssistant, @@ -98,7 +103,6 @@ async def test_selective_state_update( (0x83, "on", "on", "on"), ], ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.BINARY_SENSOR]) async def test_bitmap( hass: HomeAssistant, mock_manager: Manager, diff --git a/tests/components/tuya/test_button.py b/tests/components/tuya/test_button.py index 391691ff931..7e7ca6bf8dc 100644 --- a/tests/components/tuya/test_button.py +++ b/tests/components/tuya/test_button.py @@ -18,7 +18,13 @@ from . import initialize_entry from tests.common import MockConfigEntry, snapshot_platform -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.BUTTON]) +@pytest.fixture(autouse=True) +def platform_autouse(): + """Platform fixture.""" + with patch("homeassistant.components.tuya.PLATFORMS", [Platform.BUTTON]): + yield + + @pytest.mark.usefixtures("entity_registry_enabled_by_default") async def test_platform_setup_and_discovery( hass: HomeAssistant, @@ -34,7 +40,6 @@ async def test_platform_setup_and_discovery( await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.BUTTON]) @pytest.mark.parametrize( "mock_device_code", ["sd_lr33znaodtyarrrz"], diff --git a/tests/components/tuya/test_camera.py b/tests/components/tuya/test_camera.py index 186c411e0ce..e2fddd4bac4 100644 --- a/tests/components/tuya/test_camera.py +++ b/tests/components/tuya/test_camera.py @@ -23,6 +23,20 @@ from . import initialize_entry from tests.common import MockConfigEntry, snapshot_platform +@pytest.fixture(autouse=True) +def platform_autouse(): + """Platform fixture.""" + with ( + patch("homeassistant.components.tuya.PLATFORMS", [Platform.CAMERA]), + # Mock camera access token which normally is randomized. + patch( + "homeassistant.components.camera.SystemRandom.getrandbits", + return_value=1, + ), + ): + yield + + @pytest.fixture(autouse=True) def mock_getrandbits(): """Mock camera access token which normally is randomized.""" @@ -33,7 +47,6 @@ def mock_getrandbits(): yield -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.CAMERA]) async def test_platform_setup_and_discovery( hass: HomeAssistant, mock_manager: Manager, @@ -54,7 +67,6 @@ async def test_platform_setup_and_discovery( ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.CAMERA]) @pytest.mark.parametrize( "mock_device_code", ["sp_rudejjigkywujjvs"], diff --git a/tests/components/tuya/test_climate.py b/tests/components/tuya/test_climate.py index cbde579d34d..30880d0aa4c 100644 --- a/tests/components/tuya/test_climate.py +++ b/tests/components/tuya/test_climate.py @@ -43,7 +43,13 @@ from . import initialize_entry from tests.common import MockConfigEntry, snapshot_platform -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.CLIMATE]) +@pytest.fixture(autouse=True) +def platform_autouse(): + """Platform fixture.""" + with patch("homeassistant.components.tuya.PLATFORMS", [Platform.CLIMATE]): + yield + + async def test_platform_setup_and_discovery( hass: HomeAssistant, mock_manager: Manager, @@ -58,7 +64,6 @@ async def test_platform_setup_and_discovery( await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.CLIMATE]) async def test_us_customary_system( hass: HomeAssistant, mock_manager: Manager, diff --git a/tests/components/tuya/test_cover.py b/tests/components/tuya/test_cover.py index 3124e79f81b..b33ba332aa7 100644 --- a/tests/components/tuya/test_cover.py +++ b/tests/components/tuya/test_cover.py @@ -36,7 +36,13 @@ from . import initialize_entry from tests.common import MockConfigEntry, snapshot_platform -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.COVER]) +@pytest.fixture(autouse=True) +def platform_autouse(): + """Platform fixture.""" + with patch("homeassistant.components.tuya.PLATFORMS", [Platform.COVER]): + yield + + async def test_platform_setup_and_discovery( hass: HomeAssistant, mock_manager: Manager, @@ -112,7 +118,6 @@ async def test_platform_setup_and_discovery( ), ], ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.COVER]) async def test_action( hass: HomeAssistant, mock_manager: Manager, @@ -154,7 +159,6 @@ async def test_action( (50, 25), ], ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.COVER]) async def test_percent_state_on_cover( hass: HomeAssistant, mock_manager: Manager, @@ -218,7 +222,6 @@ async def test_set_tilt_position_not_supported( (100, "open", 100), ], ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.COVER]) async def test_clkg_wltqkykhni0papzj_state( hass: HomeAssistant, mock_manager: Manager, @@ -275,7 +278,6 @@ async def test_clkg_wltqkykhni0papzj_state( ), ], ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.COVER]) async def test_clkg_wltqkykhni0papzj_action( hass: HomeAssistant, mock_manager: Manager, @@ -321,7 +323,6 @@ async def test_clkg_wltqkykhni0papzj_action( ("close", STATE_CLOSED), ], ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.COVER]) async def test_cl_n3xgr5pdmpinictg_state( hass: HomeAssistant, mock_manager: Manager, diff --git a/tests/components/tuya/test_event.py b/tests/components/tuya/test_event.py index 7f6fec48f1c..b269eb68ef2 100644 --- a/tests/components/tuya/test_event.py +++ b/tests/components/tuya/test_event.py @@ -19,8 +19,14 @@ from . import MockDeviceListener, initialize_entry from tests.common import MockConfigEntry, snapshot_platform +@pytest.fixture(autouse=True) +def platform_autouse(): + """Platform fixture.""" + with patch("homeassistant.components.tuya.PLATFORMS", [Platform.EVENT]): + yield + + @pytest.mark.freeze_time("2023-11-01 13:14:15+01:00") -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.EVENT]) async def test_platform_setup_and_discovery( hass: HomeAssistant, mock_manager: Manager, @@ -59,7 +65,6 @@ async def test_platform_setup_and_discovery( ), ], ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.EVENT]) async def test_alarm_message_event( hass: HomeAssistant, mock_manager: Manager, @@ -88,7 +93,6 @@ async def test_alarm_message_event( "mock_device_code", ["wxkg_l8yaz4um5b3pwyvf"], ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.EVENT]) @pytest.mark.freeze_time("2024-01-01") async def test_selective_state_update( hass: HomeAssistant, diff --git a/tests/components/tuya/test_fan.py b/tests/components/tuya/test_fan.py index d65db472f59..9c6e5a5b712 100644 --- a/tests/components/tuya/test_fan.py +++ b/tests/components/tuya/test_fan.py @@ -26,7 +26,13 @@ from . import initialize_entry from tests.common import MockConfigEntry, snapshot_platform -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.FAN]) +@pytest.fixture(autouse=True) +def platform_autouse(): + """Platform fixture.""" + with patch("homeassistant.components.tuya.PLATFORMS", [Platform.FAN]): + yield + + async def test_platform_setup_and_discovery( hass: HomeAssistant, mock_manager: Manager, @@ -41,7 +47,6 @@ async def test_platform_setup_and_discovery( await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.FAN]) @pytest.mark.parametrize( ("mock_device_code", "entity_id", "service", "service_data", "expected_commands"), [ diff --git a/tests/components/tuya/test_humidifier.py b/tests/components/tuya/test_humidifier.py index 8a4d193a56b..63bc33c0338 100644 --- a/tests/components/tuya/test_humidifier.py +++ b/tests/components/tuya/test_humidifier.py @@ -26,7 +26,13 @@ from . import initialize_entry from tests.common import MockConfigEntry, snapshot_platform -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.HUMIDIFIER]) +@pytest.fixture(autouse=True) +def platform_autouse(): + """Platform fixture.""" + with patch("homeassistant.components.tuya.PLATFORMS", [Platform.HUMIDIFIER]): + yield + + async def test_platform_setup_and_discovery( hass: HomeAssistant, mock_manager: Manager, diff --git a/tests/components/tuya/test_light.py b/tests/components/tuya/test_light.py index 28d53881bdf..447b6b5a05b 100644 --- a/tests/components/tuya/test_light.py +++ b/tests/components/tuya/test_light.py @@ -27,7 +27,13 @@ from . import initialize_entry from tests.common import MockConfigEntry, snapshot_platform -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.LIGHT]) +@pytest.fixture(autouse=True) +def platform_autouse(): + """Platform fixture.""" + with patch("homeassistant.components.tuya.PLATFORMS", [Platform.LIGHT]): + yield + + async def test_platform_setup_and_discovery( hass: HomeAssistant, mock_manager: Manager, diff --git a/tests/components/tuya/test_number.py b/tests/components/tuya/test_number.py index d4ed776c56b..3875b8bd6b5 100644 --- a/tests/components/tuya/test_number.py +++ b/tests/components/tuya/test_number.py @@ -24,7 +24,13 @@ from . import MockDeviceListener, check_selective_state_update, initialize_entry from tests.common import MockConfigEntry, snapshot_platform -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.NUMBER]) +@pytest.fixture(autouse=True) +def platform_autouse(): + """Platform fixture.""" + with patch("homeassistant.components.tuya.PLATFORMS", [Platform.NUMBER]): + yield + + async def test_platform_setup_and_discovery( hass: HomeAssistant, mock_manager: Manager, @@ -59,7 +65,6 @@ async def test_platform_setup_and_discovery( ), ], ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.NUMBER]) @pytest.mark.freeze_time("2024-01-01") async def test_selective_state_update( hass: HomeAssistant, diff --git a/tests/components/tuya/test_select.py b/tests/components/tuya/test_select.py index 66a58ea8b83..731aa649b20 100644 --- a/tests/components/tuya/test_select.py +++ b/tests/components/tuya/test_select.py @@ -25,7 +25,13 @@ from . import MockDeviceListener, check_selective_state_update, initialize_entry from tests.common import MockConfigEntry, snapshot_platform -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SELECT]) +@pytest.fixture(autouse=True) +def platform_autouse(): + """Platform fixture.""" + with patch("homeassistant.components.tuya.PLATFORMS", [Platform.SELECT]): + yield + + async def test_platform_setup_and_discovery( hass: HomeAssistant, mock_manager: Manager, @@ -60,7 +66,6 @@ async def test_platform_setup_and_discovery( ), ], ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SELECT]) @pytest.mark.freeze_time("2024-01-01") async def test_selective_state_update( hass: HomeAssistant, diff --git a/tests/components/tuya/test_sensor.py b/tests/components/tuya/test_sensor.py index 80d275b893e..d2a59216161 100644 --- a/tests/components/tuya/test_sensor.py +++ b/tests/components/tuya/test_sensor.py @@ -20,7 +20,13 @@ from . import MockDeviceListener, check_selective_state_update, initialize_entry from tests.common import MockConfigEntry, snapshot_platform -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SENSOR]) +@pytest.fixture(autouse=True) +def platform_autouse(): + """Platform fixture.""" + with patch("homeassistant.components.tuya.PLATFORMS", [Platform.SENSOR]): + yield + + @pytest.mark.usefixtures("entity_registry_enabled_by_default") async def test_platform_setup_and_discovery( hass: HomeAssistant, @@ -56,7 +62,6 @@ async def test_platform_setup_and_discovery( ), ], ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SENSOR]) @pytest.mark.freeze_time("2024-01-01") async def test_selective_state_update( hass: HomeAssistant, @@ -85,7 +90,6 @@ async def test_selective_state_update( ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SENSOR]) @pytest.mark.parametrize("mock_device_code", ["cz_guitoc9iylae4axs"]) async def test_delta_report_sensor( hass: HomeAssistant, diff --git a/tests/components/tuya/test_siren.py b/tests/components/tuya/test_siren.py index e4abcaa293d..49771dd5e6a 100644 --- a/tests/components/tuya/test_siren.py +++ b/tests/components/tuya/test_siren.py @@ -24,7 +24,13 @@ from . import MockDeviceListener, check_selective_state_update, initialize_entry from tests.common import MockConfigEntry, snapshot_platform -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SIREN]) +@pytest.fixture(autouse=True) +def platform_autouse(): + """Platform fixture.""" + with patch("homeassistant.components.tuya.PLATFORMS", [Platform.SIREN]): + yield + + async def test_platform_setup_and_discovery( hass: HomeAssistant, mock_manager: Manager, @@ -59,7 +65,6 @@ async def test_platform_setup_and_discovery( ), ], ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SIREN]) @pytest.mark.freeze_time("2024-01-01") async def test_selective_state_update( hass: HomeAssistant, @@ -88,7 +93,6 @@ async def test_selective_state_update( ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SIREN]) @pytest.mark.parametrize( "mock_device_code", ["sp_sdd5f5f2dl5wydjf"], diff --git a/tests/components/tuya/test_switch.py b/tests/components/tuya/test_switch.py index 2e5bbc08609..b9705892e43 100644 --- a/tests/components/tuya/test_switch.py +++ b/tests/components/tuya/test_switch.py @@ -24,7 +24,13 @@ from . import MockDeviceListener, check_selective_state_update, initialize_entry from tests.common import MockConfigEntry, snapshot_platform -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SWITCH]) +@pytest.fixture(autouse=True) +def platform_autouse(): + """Platform fixture.""" + with patch("homeassistant.components.tuya.PLATFORMS", [Platform.SWITCH]): + yield + + async def test_platform_setup_and_discovery( hass: HomeAssistant, mock_manager: Manager, @@ -59,7 +65,6 @@ async def test_platform_setup_and_discovery( ), ], ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SWITCH]) @pytest.mark.freeze_time("2024-01-01") async def test_selective_state_update( hass: HomeAssistant, @@ -88,7 +93,6 @@ async def test_selective_state_update( ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SWITCH]) @pytest.mark.parametrize( "mock_device_code", ["cz_PGEkBctAbtzKOZng"], @@ -133,7 +137,6 @@ async def test_action( ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.SWITCH]) @pytest.mark.parametrize( "mock_device_code", ["cz_PGEkBctAbtzKOZng"], diff --git a/tests/components/tuya/test_vacuum.py b/tests/components/tuya/test_vacuum.py index 3b3bd3d3398..18ffafe8dc1 100644 --- a/tests/components/tuya/test_vacuum.py +++ b/tests/components/tuya/test_vacuum.py @@ -28,7 +28,13 @@ from . import initialize_entry from tests.common import MockConfigEntry, snapshot_platform -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.VACUUM]) +@pytest.fixture(autouse=True) +def platform_autouse(): + """Platform fixture.""" + with patch("homeassistant.components.tuya.PLATFORMS", [Platform.VACUUM]): + yield + + async def test_platform_setup_and_discovery( hass: HomeAssistant, mock_manager: Manager, diff --git a/tests/components/tuya/test_valve.py b/tests/components/tuya/test_valve.py index 8791ae499e9..b0fa504dc97 100644 --- a/tests/components/tuya/test_valve.py +++ b/tests/components/tuya/test_valve.py @@ -24,7 +24,13 @@ from . import MockDeviceListener, check_selective_state_update, initialize_entry from tests.common import MockConfigEntry, snapshot_platform -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.VALVE]) +@pytest.fixture(autouse=True) +def platform_autouse(): + """Platform fixture.""" + with patch("homeassistant.components.tuya.PLATFORMS", [Platform.VALVE]): + yield + + async def test_platform_setup_and_discovery( hass: HomeAssistant, mock_manager: Manager, @@ -59,7 +65,6 @@ async def test_platform_setup_and_discovery( ), ], ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.VALVE]) @pytest.mark.freeze_time("2024-01-01") async def test_selective_state_update( hass: HomeAssistant, @@ -88,7 +93,6 @@ async def test_selective_state_update( ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.VALVE]) @pytest.mark.parametrize( "mock_device_code", ["sfkzq_ed7frwissyqrejic"], @@ -133,7 +137,6 @@ async def test_action( ) -@patch("homeassistant.components.tuya.PLATFORMS", [Platform.VALVE]) @pytest.mark.parametrize( "mock_device_code", ["sfkzq_ed7frwissyqrejic"],