From f674559a71e0f7cee474f594bbe3d9c4c2288454 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 10 Mar 2023 16:04:45 +0100 Subject: [PATCH] Add missing mock in landisgyr config flow tests (#89513) --- .../landisgyr_heat_meter/conftest.py | 15 ++++++++++++ .../landisgyr_heat_meter/test_config_flow.py | 23 ++++++++----------- 2 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 tests/components/landisgyr_heat_meter/conftest.py diff --git a/tests/components/landisgyr_heat_meter/conftest.py b/tests/components/landisgyr_heat_meter/conftest.py new file mode 100644 index 00000000000..711fa2110f4 --- /dev/null +++ b/tests/components/landisgyr_heat_meter/conftest.py @@ -0,0 +1,15 @@ +"""Define fixtures for Landis + Gyr Heat Meter 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.landisgyr_heat_meter.async_setup_entry", + return_value=True, + ) as mock_setup_entry: + yield mock_setup_entry diff --git a/tests/components/landisgyr_heat_meter/test_config_flow.py b/tests/components/landisgyr_heat_meter/test_config_flow.py index 57638868647..b58c91f8f16 100644 --- a/tests/components/landisgyr_heat_meter/test_config_flow.py +++ b/tests/components/landisgyr_heat_meter/test_config_flow.py @@ -2,6 +2,7 @@ from dataclasses import dataclass from unittest.mock import patch +import pytest import serial import serial.tools.list_ports @@ -14,6 +15,8 @@ from tests.common import MockConfigEntry API_HEAT_METER_SERVICE = "homeassistant.components.landisgyr_heat_meter.config_flow.ultraheat_api.HeatMeterService" +pytestmark = pytest.mark.usefixtures("mock_setup_entry") + def mock_serial_port(): """Mock of a serial port.""" @@ -57,13 +60,9 @@ async def test_manual_entry(mock_heat_meter, hass: HomeAssistant) -> None: assert result["step_id"] == "setup_serial_manual_path" assert result["errors"] == {} - with patch( - "homeassistant.components.landisgyr_heat_meter.async_setup_entry", - return_value=True, - ): - result = await hass.config_entries.flow.async_configure( - result["flow_id"], {"device": "/dev/ttyUSB0"} - ) + result = await hass.config_entries.flow.async_configure( + result["flow_id"], {"device": "/dev/ttyUSB0"} + ) assert result["type"] == FlowResultType.CREATE_ENTRY assert result["title"] == "LUGCUH50" @@ -122,13 +121,9 @@ async def test_manual_entry_fail(mock_heat_meter, hass: HomeAssistant) -> None: assert result["step_id"] == "setup_serial_manual_path" assert result["errors"] == {} - with patch( - "homeassistant.components.landisgyr_heat_meter.async_setup_entry", - return_value=True, - ): - result = await hass.config_entries.flow.async_configure( - result["flow_id"], {"device": "/dev/ttyUSB0"} - ) + result = await hass.config_entries.flow.async_configure( + result["flow_id"], {"device": "/dev/ttyUSB0"} + ) assert result["type"] == FlowResultType.FORM assert result["step_id"] == "setup_serial_manual_path"