From 76819fbb231359fef98a9c74e08a93e0fd7a504c Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 27 Feb 2023 14:01:09 +0100 Subject: [PATCH] Add missing mock in brunt config flow tests (#88834) --- tests/components/brunt/conftest.py | 14 ++++++++++++++ tests/components/brunt/test_config_flow.py | 11 +++++------ 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 tests/components/brunt/conftest.py diff --git a/tests/components/brunt/conftest.py b/tests/components/brunt/conftest.py new file mode 100644 index 00000000000..8ae0bbaf317 --- /dev/null +++ b/tests/components/brunt/conftest.py @@ -0,0 +1,14 @@ +"""Configuration for brunt tests.""" +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.brunt.async_setup_entry", return_value=True + ) as mock_setup_entry: + yield mock_setup_entry diff --git a/tests/components/brunt/test_config_flow.py b/tests/components/brunt/test_config_flow.py index 93fd06e30d6..c8b0a3955c8 100644 --- a/tests/components/brunt/test_config_flow.py +++ b/tests/components/brunt/test_config_flow.py @@ -1,5 +1,5 @@ """Test the Brunt config flow.""" -from unittest.mock import Mock, patch +from unittest.mock import AsyncMock, Mock, patch from aiohttp import ClientResponseError from aiohttp.client_exceptions import ServerDisconnectedError @@ -14,8 +14,10 @@ from tests.common import MockConfigEntry CONFIG = {CONF_USERNAME: "test-username", CONF_PASSWORD: "test-password"} +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( DOMAIN, context={"source": config_entries.SOURCE_USER}, data=None @@ -26,10 +28,7 @@ async def test_form(hass: HomeAssistant) -> None: with patch( "homeassistant.components.brunt.config_flow.BruntClientAsync.async_login", return_value=None, - ), patch( - "homeassistant.components.brunt.async_setup_entry", - return_value=True, - ) as mock_setup_entry: + ): result2 = await hass.config_entries.flow.async_configure( result["flow_id"], CONFIG,