From 089874f8184440b41cba9b8f1a6d1358d29f5e6e Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 4 Jun 2024 16:05:56 +0200 Subject: [PATCH] Move mock_hass_config fixture to decorator (#118807) --- tests/components/analytics/test_analytics.py | 32 ++++++++----------- .../triggers/test_homeassistant.py | 3 +- tests/components/knx/test_diagnostic.py | 8 ++--- tests/components/mqtt/test_init.py | 2 +- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/tests/components/analytics/test_analytics.py b/tests/components/analytics/test_analytics.py index 587b8600f3f..8b86c505517 100644 --- a/tests/components/analytics/test_analytics.py +++ b/tests/components/analytics/test_analytics.py @@ -266,11 +266,11 @@ async def test_send_usage( assert snapshot == submitted_data +@pytest.mark.usefixtures("mock_hass_config") async def test_send_usage_with_supervisor( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, aioclient_mock: AiohttpClientMocker, - mock_hass_config: None, snapshot: SnapshotAssertion, ) -> None: """Test send usage with supervisor preferences are defined.""" @@ -359,11 +359,9 @@ async def test_send_statistics( assert snapshot == submitted_data +@pytest.mark.usefixtures("mock_hass_config") async def test_send_statistics_one_integration_fails( - hass: HomeAssistant, - caplog: pytest.LogCaptureFixture, - aioclient_mock: AiohttpClientMocker, - mock_hass_config: None, + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker ) -> None: """Test send statistics preferences are defined.""" aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200) @@ -384,11 +382,11 @@ async def test_send_statistics_one_integration_fails( assert post_call[2]["integration_count"] == 0 +@pytest.mark.usefixtures("mock_hass_config") async def test_send_statistics_disabled_integration( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, aioclient_mock: AiohttpClientMocker, - mock_hass_config: None, installation_type_mock: Generator[Any, Any, None], snapshot: SnapshotAssertion, ) -> None: @@ -422,11 +420,11 @@ async def test_send_statistics_disabled_integration( assert snapshot == submitted_data +@pytest.mark.usefixtures("mock_hass_config") async def test_send_statistics_ignored_integration( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, aioclient_mock: AiohttpClientMocker, - mock_hass_config: None, installation_type_mock: Generator[Any, Any, None], snapshot: SnapshotAssertion, ) -> None: @@ -466,11 +464,9 @@ async def test_send_statistics_ignored_integration( assert snapshot == submitted_data +@pytest.mark.usefixtures("mock_hass_config") async def test_send_statistics_async_get_integration_unknown_exception( - hass: HomeAssistant, - caplog: pytest.LogCaptureFixture, - aioclient_mock: AiohttpClientMocker, - mock_hass_config: None, + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker ) -> None: """Test send statistics preferences are defined.""" aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200) @@ -490,11 +486,11 @@ async def test_send_statistics_async_get_integration_unknown_exception( await analytics.send_analytics() +@pytest.mark.usefixtures("mock_hass_config") async def test_send_statistics_with_supervisor( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, aioclient_mock: AiohttpClientMocker, - mock_hass_config: None, snapshot: SnapshotAssertion, ) -> None: """Test send statistics preferences are defined.""" @@ -655,10 +651,10 @@ async def test_nightly_endpoint( assert str(payload[1]) == ANALYTICS_ENDPOINT_URL +@pytest.mark.usefixtures("mock_hass_config") async def test_send_with_no_energy( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, - mock_hass_config: None, caplog: pytest.LogCaptureFixture, installation_type_mock: Generator[Any, Any, None], snapshot: SnapshotAssertion, @@ -692,11 +688,10 @@ async def test_send_with_no_energy( assert snapshot == submitted_data +@pytest.mark.usefixtures("recorder_mock", "mock_hass_config") async def test_send_with_no_energy_config( - recorder_mock: Recorder, hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, - mock_hass_config: None, caplog: pytest.LogCaptureFixture, installation_type_mock: Generator[Any, Any, None], snapshot: SnapshotAssertion, @@ -725,11 +720,10 @@ async def test_send_with_no_energy_config( ) +@pytest.mark.usefixtures("recorder_mock", "mock_hass_config") async def test_send_with_energy_config( - recorder_mock: Recorder, hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, - mock_hass_config: None, caplog: pytest.LogCaptureFixture, installation_type_mock: Generator[Any, Any, None], snapshot: SnapshotAssertion, @@ -758,11 +752,11 @@ async def test_send_with_energy_config( ) +@pytest.mark.usefixtures("mock_hass_config") async def test_send_usage_with_certificate( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, aioclient_mock: AiohttpClientMocker, - mock_hass_config: None, installation_type_mock: Generator[Any, Any, None], snapshot: SnapshotAssertion, ) -> None: @@ -836,11 +830,11 @@ async def test_send_with_problems_loading_yaml( assert len(aioclient_mock.mock_calls) == 0 +@pytest.mark.usefixtures("mock_hass_config") async def test_timeout_while_sending( hass: HomeAssistant, caplog: pytest.LogCaptureFixture, aioclient_mock: AiohttpClientMocker, - mock_hass_config: None, ) -> None: """Test timeout error while sending analytics.""" analytics = Analytics(hass) diff --git a/tests/components/homeassistant/triggers/test_homeassistant.py b/tests/components/homeassistant/triggers/test_homeassistant.py index 2afb533cdc0..9c552a0324b 100644 --- a/tests/components/homeassistant/triggers/test_homeassistant.py +++ b/tests/components/homeassistant/triggers/test_homeassistant.py @@ -27,8 +27,9 @@ from tests.common import async_mock_service } ], ) +@pytest.mark.usefixtures("mock_hass_config") async def test_if_fires_on_hass_start( - hass: HomeAssistant, mock_hass_config: None, hass_config: ConfigType + hass: HomeAssistant, hass_config: ConfigType ) -> None: """Test the firing when Home Assistant starts.""" calls = async_mock_service(hass, "test", "automation") diff --git a/tests/components/knx/test_diagnostic.py b/tests/components/knx/test_diagnostic.py index 0b43433c01e..bb60e66f7e7 100644 --- a/tests/components/knx/test_diagnostic.py +++ b/tests/components/knx/test_diagnostic.py @@ -31,12 +31,12 @@ from tests.typing import ClientSessionGenerator @pytest.mark.parametrize("hass_config", [{}]) +@pytest.mark.usefixtures("mock_hass_config") async def test_diagnostics( hass: HomeAssistant, hass_client: ClientSessionGenerator, mock_config_entry: MockConfigEntry, knx: KNXTestKit, - mock_hass_config: None, snapshot: SnapshotAssertion, ) -> None: """Test diagnostics.""" @@ -51,9 +51,9 @@ async def test_diagnostics( @pytest.mark.parametrize("hass_config", [{"knx": {"wrong_key": {}}}]) +@pytest.mark.usefixtures("mock_hass_config") async def test_diagnostic_config_error( hass: HomeAssistant, - mock_hass_config: None, hass_client: ClientSessionGenerator, mock_config_entry: MockConfigEntry, knx: KNXTestKit, @@ -72,10 +72,10 @@ async def test_diagnostic_config_error( @pytest.mark.parametrize("hass_config", [{}]) +@pytest.mark.usefixtures("mock_hass_config") async def test_diagnostic_redact( hass: HomeAssistant, hass_client: ClientSessionGenerator, - mock_hass_config: None, snapshot: SnapshotAssertion, ) -> None: """Test diagnostics redacting data.""" @@ -107,12 +107,12 @@ async def test_diagnostic_redact( @pytest.mark.parametrize("hass_config", [{}]) +@pytest.mark.usefixtures("mock_hass_config") async def test_diagnostics_project( hass: HomeAssistant, hass_client: ClientSessionGenerator, mock_config_entry: MockConfigEntry, knx: KNXTestKit, - mock_hass_config: None, load_knxproj: None, snapshot: SnapshotAssertion, ) -> None: diff --git a/tests/components/mqtt/test_init.py b/tests/components/mqtt/test_init.py index 50b22e986b0..2b9e4260c7e 100644 --- a/tests/components/mqtt/test_init.py +++ b/tests/components/mqtt/test_init.py @@ -928,9 +928,9 @@ def test_entity_device_info_schema() -> None: } ], ) +@pytest.mark.usefixtures("mock_hass_config") async def test_handle_logging_on_writing_the_entity_state( hass: HomeAssistant, - mock_hass_config: None, mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, ) -> None: