diff --git a/tests/components/buienradar/conftest.py b/tests/components/buienradar/conftest.py new file mode 100644 index 00000000000..b896e54e628 --- /dev/null +++ b/tests/components/buienradar/conftest.py @@ -0,0 +1,14 @@ +"""Test fixtures for buienradar2.""" +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.buienradar.async_setup_entry", return_value=True + ) as mock_setup_entry: + yield mock_setup_entry diff --git a/tests/components/buienradar/test_config_flow.py b/tests/components/buienradar/test_config_flow.py index 955a7b85dc8..6a7db5e9066 100644 --- a/tests/components/buienradar/test_config_flow.py +++ b/tests/components/buienradar/test_config_flow.py @@ -1,5 +1,6 @@ """Test the buienradar2 config flow.""" -from unittest.mock import patch + +import pytest from homeassistant import config_entries, data_entry_flow from homeassistant.components.buienradar.const import DOMAIN @@ -11,6 +12,8 @@ from tests.common import MockConfigEntry TEST_LATITUDE = 51.5288504 TEST_LONGITUDE = 5.4002156 +pytestmark = pytest.mark.usefixtures("mock_setup_entry") + async def test_config_flow_setup_(hass: HomeAssistant) -> None: """Test setup of camera.""" @@ -22,13 +25,10 @@ async def test_config_flow_setup_(hass: HomeAssistant) -> None: assert result["step_id"] == "user" assert result["errors"] == {} - with patch( - "homeassistant.components.buienradar.async_setup_entry", return_value=True - ): - result = await hass.config_entries.flow.async_configure( - result["flow_id"], - {CONF_LATITUDE: TEST_LATITUDE, CONF_LONGITUDE: TEST_LONGITUDE}, - ) + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + {CONF_LATITUDE: TEST_LATITUDE, CONF_LONGITUDE: TEST_LONGITUDE}, + ) assert result["type"] == "create_entry" assert result["title"] == f"{TEST_LATITUDE},{TEST_LONGITUDE}" @@ -92,13 +92,8 @@ async def test_options_flow(hass: HomeAssistant) -> None: user_input={"country_code": "BE", "delta": 450, "timeframe": 30}, ) - with patch( - "homeassistant.components.buienradar.async_setup_entry", return_value=True - ), patch( - "homeassistant.components.buienradar.async_unload_entry", return_value=True - ): - assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY + assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY - await hass.async_block_till_done() + await hass.async_block_till_done() assert entry.options == {"country_code": "BE", "delta": 450, "timeframe": 30}