diff --git a/tests/components/lacrosse_view/conftest.py b/tests/components/lacrosse_view/conftest.py new file mode 100644 index 00000000000..1ea3144e4c2 --- /dev/null +++ b/tests/components/lacrosse_view/conftest.py @@ -0,0 +1,14 @@ +"""Define fixtures for LaCrosse View 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.lacrosse_view.async_setup_entry", return_value=True + ) as mock_setup_entry: + yield mock_setup_entry diff --git a/tests/components/lacrosse_view/test_config_flow.py b/tests/components/lacrosse_view/test_config_flow.py index 67c9bf5752c..075aa7a3767 100644 --- a/tests/components/lacrosse_view/test_config_flow.py +++ b/tests/components/lacrosse_view/test_config_flow.py @@ -1,7 +1,8 @@ """Test the LaCrosse View config flow.""" -from unittest.mock import patch +from unittest.mock import AsyncMock, patch from lacrosse_view import Location, LoginError +import pytest from homeassistant import config_entries from homeassistant.components.lacrosse_view.const import DOMAIN @@ -10,8 +11,10 @@ from homeassistant.data_entry_flow import FlowResultType from tests.common import MockConfigEntry +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} @@ -25,8 +28,6 @@ async def test_form(hass: HomeAssistant) -> None: ), patch( "lacrosse_view.LaCrosse.get_locations", return_value=[Location(id=1, name="Test")], - ), patch( - "homeassistant.components.lacrosse_view.async_setup_entry", return_value=True ): result2 = await hass.config_entries.flow.async_configure( result["flow_id"], @@ -41,17 +42,13 @@ async def test_form(hass: HomeAssistant) -> None: assert result2["step_id"] == "location" assert result2["errors"] is None - with patch( - "homeassistant.components.lacrosse_view.async_setup_entry", - return_value=True, - ) as mock_setup_entry: - result3 = await hass.config_entries.flow.async_configure( - result2["flow_id"], - { - "location": "1", - }, - ) - await hass.async_block_till_done() + result3 = await hass.config_entries.flow.async_configure( + result2["flow_id"], + { + "location": "1", + }, + ) + await hass.async_block_till_done() assert result3["type"] == FlowResultType.CREATE_ENTRY assert result3["title"] == "Test" @@ -170,7 +167,9 @@ async def test_form_unexpected_error(hass: HomeAssistant) -> None: assert result2["errors"] == {"base": "unknown"} -async def test_already_configured_device(hass: HomeAssistant) -> None: +async def test_already_configured_device( + hass: HomeAssistant, mock_setup_entry: AsyncMock +) -> None: """Test we handle invalid auth.""" mock_config_entry = MockConfigEntry( domain=DOMAIN, @@ -212,17 +211,13 @@ async def test_already_configured_device(hass: HomeAssistant) -> None: assert result2["step_id"] == "location" assert result2["errors"] is None - with patch( - "homeassistant.components.lacrosse_view.async_setup_entry", - return_value=True, - ) as mock_setup_entry: - result3 = await hass.config_entries.flow.async_configure( - result2["flow_id"], - { - "location": "1", - }, - ) - await hass.async_block_till_done() + result3 = await hass.config_entries.flow.async_configure( + result2["flow_id"], + { + "location": "1", + }, + ) + await hass.async_block_till_done() assert result3["type"] == FlowResultType.ABORT assert result3["reason"] == "already_configured"