From 4a082403eb9886ba2df42c4d9cd3d014265a0b82 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 9 Mar 2023 13:16:36 +0100 Subject: [PATCH] Add missing mock in coronavirus config flow tests (#89428) --- tests/components/coronavirus/conftest.py | 13 +++++++++++-- tests/components/coronavirus/test_config_flow.py | 9 ++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/components/coronavirus/conftest.py b/tests/components/coronavirus/conftest.py index 57128268fd7..227d9fa2123 100644 --- a/tests/components/coronavirus/conftest.py +++ b/tests/components/coronavirus/conftest.py @@ -1,10 +1,19 @@ """Test helpers.""" - -from unittest.mock import Mock, patch +from collections.abc import Generator +from unittest.mock import AsyncMock, Mock, patch import pytest +@pytest.fixture +def mock_setup_entry() -> Generator[AsyncMock, None, None]: + """Override async_setup_entry.""" + with patch( + "homeassistant.components.coronavirus.async_setup_entry", return_value=True + ) as mock_setup_entry: + yield mock_setup_entry + + @pytest.fixture(autouse=True) def mock_cases(): """Mock coronavirus cases.""" diff --git a/tests/components/coronavirus/test_config_flow.py b/tests/components/coronavirus/test_config_flow.py index e641c0e0011..2fe7ed370e8 100644 --- a/tests/components/coronavirus/test_config_flow.py +++ b/tests/components/coronavirus/test_config_flow.py @@ -1,14 +1,17 @@ """Test the Coronavirus config flow.""" -from unittest.mock import MagicMock, patch +from unittest.mock import AsyncMock, MagicMock, patch from aiohttp import ClientError +import pytest from homeassistant import config_entries from homeassistant.components.coronavirus.const import DOMAIN, OPTION_WORLDWIDE from homeassistant.core import HomeAssistant +pytestmark = pytest.mark.usefixtures("mock_setup_entry") -async def test_form(hass: HomeAssistant) -> None: + +async def test_form(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None: """Test we get the form.""" result = await hass.config_entries.flow.async_init( @@ -28,7 +31,7 @@ async def test_form(hass: HomeAssistant) -> None: "country": OPTION_WORLDWIDE, } await hass.async_block_till_done() - assert len(hass.states.async_all()) == 4 + mock_setup_entry.assert_called_once() @patch(