From 8a9c0f4fde47041f2ee37911f1c654d550c44ed3 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 31 Mar 2026 14:49:54 +0200 Subject: [PATCH] Fix lingering tasks in nest tests (#166959) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- tests/components/nest/conftest.py | 10 ++++++++++ tests/components/nest/test_config_flow.py | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/tests/components/nest/conftest.py b/tests/components/nest/conftest.py index 2f417aba913..f4484ef0b01 100644 --- a/tests/components/nest/conftest.py +++ b/tests/components/nest/conftest.py @@ -203,6 +203,16 @@ def mock_subscriber() -> YieldFixture[AsyncMock]: yield mock_subscriber +@pytest.fixture +def mock_subscriber_refresh() -> YieldFixture[None]: + """Fixture for mocking subscriber refresh.""" + with patch( + "homeassistant.components.nest.api.GoogleNestSubscriber._async_run_refresh", + new=AsyncMock(), + ): + yield + + @pytest.fixture async def device_id() -> str: """Fixture to set default device id used when creating devices.""" diff --git a/tests/components/nest/test_config_flow.py b/tests/components/nest/test_config_flow.py index 9ff7713e9ed..7b7629cb70b 100644 --- a/tests/components/nest/test_config_flow.py +++ b/tests/components/nest/test_config_flow.py @@ -497,6 +497,7 @@ def mock_pubsub_api_responses_fixture( "user-managed-topic-existing-subscription", ], ) +@pytest.mark.usefixtures("mock_subscriber_refresh") async def test_full_flow( hass: HomeAssistant, oauth: OAuthFixture, @@ -641,6 +642,7 @@ async def test_full_flow( "user-managed-topic-existing-subscription", ], ) +@pytest.mark.usefixtures("mock_subscriber_refresh") async def test_config_flow_restart( hass: HomeAssistant, oauth: OAuthFixture, @@ -701,6 +703,7 @@ async def test_config_flow_restart( } +@pytest.mark.usefixtures("mock_subscriber_refresh") @pytest.mark.parametrize(("sdm_managed_topic"), [True]) async def test_config_flow_wrong_project_id( hass: HomeAssistant, @@ -763,6 +766,7 @@ async def test_config_flow_wrong_project_id( ("create_subscription_status"), [HTTPStatus.NOT_FOUND, HTTPStatus.INTERNAL_SERVER_ERROR, HTTPStatus.UNAUTHORIZED], ) +@pytest.mark.usefixtures("mock_subscriber_refresh") async def test_config_flow_pubsub_create_subscription_failure( hass: HomeAssistant, oauth: OAuthFixture, @@ -872,6 +876,7 @@ async def test_config_flow_pubsub_create_subscription_failure( ), ], ) +@pytest.mark.usefixtures("mock_subscriber_refresh") async def test_multiple_config_entries( hass: HomeAssistant, oauth: OAuthFixture, @@ -1026,6 +1031,7 @@ async def test_pubsub_subscriber_config_entry_reauth( @pytest.mark.parametrize(("sdm_managed_topic"), [(True)]) +@pytest.mark.usefixtures("mock_subscriber_refresh") async def test_config_entry_title_from_home( hass: HomeAssistant, oauth: OAuthFixture, @@ -1078,6 +1084,7 @@ async def test_config_entry_title_from_home( (False, {"selected_topic": "create_new_topic"}), ], ) +@pytest.mark.usefixtures("mock_subscriber_refresh") async def test_config_entry_title_multiple_homes( hass: HomeAssistant, oauth: OAuthFixture, @@ -1159,6 +1166,7 @@ async def test_title_failure_fallback( @pytest.mark.parametrize(("sdm_managed_topic"), [(True)]) +@pytest.mark.usefixtures("mock_subscriber_refresh") async def test_structure_missing_trait( hass: HomeAssistant, oauth: OAuthFixture, auth: FakeAuth ) -> None: @@ -1312,6 +1320,7 @@ async def test_dhcp_discovery_already_setup( "user-managed-select-existing-subscription", ], ) +@pytest.mark.usefixtures("mock_subscriber_refresh") async def test_dhcp_discovery_with_creds( hass: HomeAssistant, oauth: OAuthFixture, @@ -1407,6 +1416,7 @@ async def test_token_error( ) ], ) +@pytest.mark.usefixtures("mock_subscriber_refresh") async def test_existing_topic_and_subscription( hass: HomeAssistant, oauth: OAuthFixture, @@ -1448,6 +1458,7 @@ async def test_existing_topic_and_subscription( } +@pytest.mark.usefixtures("mock_subscriber_refresh") async def test_no_eligible_topics( hass: HomeAssistant, oauth: OAuthFixture, @@ -1520,6 +1531,7 @@ async def test_list_topics_failure( assert result.get("reason") == "pubsub_api_error" +@pytest.mark.usefixtures("mock_subscriber_refresh") async def test_create_topic_failed( hass: HomeAssistant, oauth: OAuthFixture, @@ -1607,6 +1619,7 @@ async def test_create_topic_failed( @pytest.mark.parametrize(("sdm_managed_topic"), [(True)]) +@pytest.mark.usefixtures("mock_subscriber_refresh") async def test_list_subscriptions_failure( hass: HomeAssistant, oauth: OAuthFixture,