From ac6bbc2f1c6e1e32c3f2c9456c89fe92771b3e0c Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 28 Feb 2023 18:04:40 +0100 Subject: [PATCH] Add missing mock in webostv config flow tests (#88913) --- tests/components/webostv/conftest.py | 10 ++++++++++ tests/components/webostv/test_config_flow.py | 18 +++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/tests/components/webostv/conftest.py b/tests/components/webostv/conftest.py index 5a55ac492df..b78046c22ec 100644 --- a/tests/components/webostv/conftest.py +++ b/tests/components/webostv/conftest.py @@ -1,4 +1,5 @@ """Common fixtures and objects for the LG webOS integration tests.""" +from collections.abc import Generator from unittest.mock import AsyncMock, Mock, patch import pytest @@ -10,6 +11,15 @@ from .const import CHANNEL_1, CHANNEL_2, CLIENT_KEY, FAKE_UUID, MOCK_APPS, MOCK_ from tests.common import async_mock_service +@pytest.fixture +def mock_setup_entry() -> Generator[AsyncMock, None, None]: + """Override async_setup_entry.""" + with patch( + "homeassistant.components.webostv.async_setup_entry", return_value=True + ) as mock_setup_entry: + yield mock_setup_entry + + @pytest.fixture def calls(hass): """Track calls to a mock service.""" diff --git a/tests/components/webostv/test_config_flow.py b/tests/components/webostv/test_config_flow.py index cc588c9c217..ad57b4647ea 100644 --- a/tests/components/webostv/test_config_flow.py +++ b/tests/components/webostv/test_config_flow.py @@ -1,6 +1,6 @@ """Test the WebOS Tv config flow.""" import dataclasses -from unittest.mock import Mock, patch +from unittest.mock import Mock from aiowebostv import WebOsTvPairError import pytest @@ -16,6 +16,8 @@ from homeassistant.data_entry_flow import FlowResultType from . import setup_webostv from .const import CLIENT_KEY, FAKE_UUID, HOST, MOCK_APPS, MOCK_INPUTS, TV_NAME +pytestmark = pytest.mark.usefixtures("mock_setup_entry") + MOCK_USER_CONFIG = { CONF_HOST: HOST, CONF_NAME: TV_NAME, @@ -65,10 +67,9 @@ async def test_form(hass: HomeAssistant, client) -> None: assert result["type"] == FlowResultType.FORM assert result["step_id"] == "pairing" - with patch("homeassistant.components.webostv.async_setup_entry", return_value=True): - result = await hass.config_entries.flow.async_configure( - result["flow_id"], user_input={} - ) + result = await hass.config_entries.flow.async_configure( + result["flow_id"], user_input={} + ) await hass.async_block_till_done() @@ -184,10 +185,9 @@ async def test_form_ssdp(hass: HomeAssistant, client) -> None: """Test that the ssdp confirmation form is served.""" assert client - with patch("homeassistant.components.webostv.async_setup_entry", return_value=True): - result = await hass.config_entries.flow.async_init( - DOMAIN, context={CONF_SOURCE: SOURCE_SSDP}, data=MOCK_DISCOVERY_INFO - ) + result = await hass.config_entries.flow.async_init( + DOMAIN, context={CONF_SOURCE: SOURCE_SSDP}, data=MOCK_DISCOVERY_INFO + ) await hass.async_block_till_done() assert result["type"] == FlowResultType.FORM