diff --git a/homeassistant/components/sabnzbd/__init__.py b/homeassistant/components/sabnzbd/__init__.py index 0b8b6e92eb3..2e345905d50 100644 --- a/homeassistant/components/sabnzbd/__init__.py +++ b/homeassistant/components/sabnzbd/__init__.py @@ -237,7 +237,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: except SabnzbdApiException as err: _LOGGER.error(err) - async_track_time_interval(hass, async_update_sabnzbd, UPDATE_INTERVAL) + entry.async_on_unload( + async_track_time_interval(hass, async_update_sabnzbd, UPDATE_INTERVAL) + ) await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) diff --git a/tests/components/sabnzbd/conftest.py b/tests/components/sabnzbd/conftest.py new file mode 100644 index 00000000000..01cea606654 --- /dev/null +++ b/tests/components/sabnzbd/conftest.py @@ -0,0 +1,14 @@ +"""Configuration for Sabnzbd 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.sabnzbd.async_setup_entry", return_value=True + ) as mock_setup_entry: + yield mock_setup_entry diff --git a/tests/components/sabnzbd/test_config_flow.py b/tests/components/sabnzbd/test_config_flow.py index 721880dd8c9..05040186bb3 100644 --- a/tests/components/sabnzbd/test_config_flow.py +++ b/tests/components/sabnzbd/test_config_flow.py @@ -1,7 +1,8 @@ """Define tests for the Sabnzbd config flow.""" -from unittest.mock import patch +from unittest.mock import AsyncMock, patch from pysabnzbd import SabnzbdApiException +import pytest from homeassistant import config_entries, data_entry_flow from homeassistant.components.sabnzbd import DOMAIN @@ -31,8 +32,10 @@ VALID_CONFIG_OLD = { CONF_SSL: False, } +pytestmark = pytest.mark.usefixtures("mock_setup_entry") -async def test_create_entry(hass: HomeAssistant) -> None: + +async def test_create_entry(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None: """Test that the user step works.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -43,10 +46,7 @@ async def test_create_entry(hass: HomeAssistant) -> None: with patch( "homeassistant.components.sabnzbd.sab.SabnzbdApi.check_available", return_value=True, - ), patch( - "homeassistant.components.sabnzbd.async_setup_entry", - return_value=True, - ) as mock_setup_entry: + ): result2 = await hass.config_entries.flow.async_configure( result["flow_id"], VALID_CONFIG,