From 3e2ee7cd11022a9fa2adf24c2d0f4951b1893a8c Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 8 Mar 2023 16:18:44 +0100 Subject: [PATCH] Add missing mock in aemet config flow tests (#89360) --- tests/components/aemet/conftest.py | 14 ++++++++++++++ tests/components/aemet/test_config_flow.py | 12 ++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 tests/components/aemet/conftest.py diff --git a/tests/components/aemet/conftest.py b/tests/components/aemet/conftest.py new file mode 100644 index 00000000000..606f01c5403 --- /dev/null +++ b/tests/components/aemet/conftest.py @@ -0,0 +1,14 @@ +"""Test fixtures for aemet.""" +from collections.abc import Generator +from unittest.mock import AsyncMock, patch + +import pytest + + +@pytest.fixture +def mock_setup_entry() -> Generator[AsyncMock, None, None]: + """Override async_setup_entry.""" + with patch( + "homeassistant.components.aemet.async_setup_entry", return_value=True + ) as mock_setup_entry: + yield mock_setup_entry diff --git a/tests/components/aemet/test_config_flow.py b/tests/components/aemet/test_config_flow.py index 9abf626a5d0..8ec16d313f7 100644 --- a/tests/components/aemet/test_config_flow.py +++ b/tests/components/aemet/test_config_flow.py @@ -1,6 +1,7 @@ """Define tests for the AEMET OpenData config flow.""" -from unittest.mock import MagicMock, patch +from unittest.mock import AsyncMock, MagicMock, patch +import pytest import requests_mock from homeassistant import data_entry_flow @@ -14,6 +15,8 @@ from .util import aemet_requests_mock from tests.common import MockConfigEntry +pytestmark = pytest.mark.usefixtures("mock_setup_entry") + CONFIG = { CONF_NAME: "aemet", CONF_API_KEY: "foo", @@ -22,13 +25,10 @@ CONFIG = { } -async def test_form(hass: HomeAssistant) -> None: +async def test_form(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None: """Test that the form is served with valid input.""" - with patch( - "homeassistant.components.aemet.async_setup_entry", - return_value=True, - ) as mock_setup_entry, requests_mock.mock() as _m: + with requests_mock.mock() as _m: aemet_requests_mock(_m) result = await hass.config_entries.flow.async_init(