From 30884f6d178ff4b86432325e2a9e76638db82ff6 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 8 Mar 2023 09:38:55 +0100 Subject: [PATCH] Add missing mock in axis config flow tests (#89365) --- tests/components/axis/conftest.py | 13 ++++++++++++- tests/components/axis/test_config_flow.py | 19 +++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/tests/components/axis/conftest.py b/tests/components/axis/conftest.py index 6be1793cc24..5c9c4e5a255 100644 --- a/tests/components/axis/conftest.py +++ b/tests/components/axis/conftest.py @@ -1,8 +1,9 @@ """Axis conftest.""" from __future__ import annotations +from collections.abc import Generator from copy import deepcopy -from unittest.mock import patch +from unittest.mock import AsyncMock, patch from axis.rtsp import Signal, State import pytest @@ -41,6 +42,16 @@ from .const import ( from tests.common import MockConfigEntry from tests.components.light.conftest import mock_light_profiles # noqa: F401 + +@pytest.fixture +def mock_setup_entry() -> Generator[AsyncMock, None, None]: + """Override async_setup_entry.""" + with patch( + "homeassistant.components.axis.async_setup_entry", return_value=True + ) as mock_setup_entry: + yield mock_setup_entry + + # Config entry fixtures diff --git a/tests/components/axis/test_config_flow.py b/tests/components/axis/test_config_flow.py index 2f2b4b52fb4..2c5b3a50513 100644 --- a/tests/components/axis/test_config_flow.py +++ b/tests/components/axis/test_config_flow.py @@ -38,16 +38,15 @@ from tests.common import MockConfigEntry @pytest.fixture(name="mock_config_entry") -async def mock_config_entry_fixture(hass, config_entry): +async def mock_config_entry_fixture(hass, config_entry, mock_setup_entry): """Mock config entry and setup entry.""" - with patch("homeassistant.components.axis.async_setup_entry", return_value=True): - assert await hass.config_entries.async_setup(config_entry.entry_id) - await hass.async_block_till_done() - yield config_entry + assert await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + return config_entry async def test_flow_manual_configuration( - hass: HomeAssistant, setup_default_vapix_requests + hass: HomeAssistant, setup_default_vapix_requests, mock_setup_entry ) -> None: """Test that config flow works.""" MockConfigEntry(domain=AXIS_DOMAIN, source=SOURCE_IGNORE).add_to_hass(hass) @@ -164,7 +163,7 @@ async def test_flow_fails_cannot_connect(hass: HomeAssistant) -> None: async def test_flow_create_entry_multiple_existing_entries_of_same_model( - hass: HomeAssistant, setup_default_vapix_requests + hass: HomeAssistant, setup_default_vapix_requests, mock_setup_entry ) -> None: """Test that create entry can generate a name with other entries.""" entry = MockConfigEntry( @@ -310,7 +309,11 @@ async def test_reauth_flow_update_configuration( ], ) async def test_discovery_flow( - hass: HomeAssistant, setup_default_vapix_requests, source: str, discovery_info: dict + hass: HomeAssistant, + setup_default_vapix_requests, + source: str, + discovery_info: dict, + mock_setup_entry, ) -> None: """Test the different discovery flows for new devices work.""" result = await hass.config_entries.flow.async_init(