Move mock_setup_entry to conftest (#88484)

This commit is contained in:
epenet 2023-03-06 11:31:50 +01:00 committed by GitHub
parent ea4d2bd1e8
commit bf5f7c53d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 115 additions and 89 deletions

View file

@ -0,0 +1,14 @@
"""Test the NEW_NAME config flow."""
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.NEW_DOMAIN.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry

View file

@ -1,5 +1,4 @@
"""Test the NEW_NAME config flow.""" """Test the NEW_NAME config flow."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
@ -10,14 +9,7 @@ from homeassistant.components.NEW_DOMAIN.const import DOMAIN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType from homeassistant.data_entry_flow import FlowResultType
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
@pytest.fixture(autouse=True, name="mock_setup_entry")
def override_async_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.NEW_DOMAIN.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
async def test_form(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None: async def test_form(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:

View file

@ -0,0 +1,14 @@
"""Test the NEW_NAME config flow."""
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.NEW_DOMAIN.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry

View file

@ -1,6 +1,5 @@
"""Test the NEW_NAME config flow.""" """Test the NEW_NAME config flow."""
from collections.abc import Generator from unittest.mock import AsyncMock
from unittest.mock import AsyncMock, patch
import pytest import pytest
@ -11,14 +10,7 @@ from homeassistant.data_entry_flow import FlowResultType
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
@pytest.fixture(autouse=True, name="mock_setup_entry")
def override_async_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.NEW_DOMAIN.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
@pytest.mark.parametrize("platform", ("sensor",)) @pytest.mark.parametrize("platform", ("sensor",))

View file

@ -1,5 +1,5 @@
"""Test configuration for Nibe Heat Pump.""" """Test configuration for Nibe Heat Pump."""
from collections.abc import AsyncIterator, Iterable from collections.abc import AsyncIterator, Generator, Iterable
from contextlib import ExitStack from contextlib import ExitStack
from typing import Any from typing import Any
from unittest.mock import AsyncMock, Mock, patch from unittest.mock import AsyncMock, Mock, patch
@ -10,6 +10,15 @@ from nibe.exceptions import ReadException
import pytest import pytest
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Make sure we never actually run setup."""
with patch(
"homeassistant.components.nibe_heatpump.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
@pytest.fixture(autouse=True, name="mock_connection_constructor") @pytest.fixture(autouse=True, name="mock_connection_constructor")
async def fixture_mock_connection_constructor(): async def fixture_mock_connection_constructor():
"""Make sure we have a dummy connection.""" """Make sure we have a dummy connection."""

View file

@ -1,5 +1,5 @@
"""Test the Nibe Heat Pump config flow.""" """Test the Nibe Heat Pump config flow."""
from unittest.mock import Mock, patch from unittest.mock import Mock
from nibe.coil import Coil from nibe.coil import Coil
from nibe.exceptions import ( from nibe.exceptions import (
@ -32,13 +32,7 @@ MOCK_FLOW_MODBUS_USERDATA = {
} }
@pytest.fixture(autouse=True, name="mock_setup_entry") pytestmark = pytest.mark.usefixtures("mock_setup_entry")
async def fixture_mock_setup():
"""Make sure we never actually run setup."""
with patch(
"homeassistant.components.nibe_heatpump.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
async def _get_connection_form( async def _get_connection_form(

View file

@ -1,5 +1,6 @@
"""Provide common 1-Wire fixtures.""" """Provide common 1-Wire fixtures."""
from unittest.mock import MagicMock, patch from collections.abc import Generator
from unittest.mock import AsyncMock, MagicMock, patch
from pyownet.protocol import ConnError from pyownet.protocol import ConnError
import pytest import pytest
@ -14,6 +15,15 @@ from .const import MOCK_OWPROXY_DEVICES
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.onewire.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
@pytest.fixture(name="device_id", params=MOCK_OWPROXY_DEVICES.keys()) @pytest.fixture(name="device_id", params=MOCK_OWPROXY_DEVICES.keys())
def get_device_id(request: pytest.FixtureRequest) -> str: def get_device_id(request: pytest.FixtureRequest) -> str:
"""Parametrize device id.""" """Parametrize device id."""

View file

@ -1,5 +1,4 @@
"""Tests for 1-Wire config flow.""" """Tests for 1-Wire config flow."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
from pyownet import protocol from pyownet import protocol
@ -19,14 +18,7 @@ from homeassistant.helpers.config_validation import ensure_list
from .const import MOCK_OWPROXY_DEVICES from .const import MOCK_OWPROXY_DEVICES
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
@pytest.fixture(autouse=True, name="mock_setup_entry")
def override_async_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.onewire.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
@pytest.fixture @pytest.fixture

View file

@ -1,5 +1,6 @@
"""Standard setup for tests.""" """Standard setup for tests."""
from unittest.mock import create_autospec, patch from collections.abc import Generator
from unittest.mock import AsyncMock, create_autospec, patch
from haphilipsjs import PhilipsTV from haphilipsjs import PhilipsTV
import pytest import pytest
@ -11,6 +12,17 @@ from . import MOCK_CONFIG, MOCK_ENTITY_ID, MOCK_NAME, MOCK_SERIAL_NO, MOCK_SYSTE
from tests.common import MockConfigEntry, mock_device_registry from tests.common import MockConfigEntry, mock_device_registry
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Disable component setup."""
with patch(
"homeassistant.components.philips_js.async_setup_entry", return_value=True
) as mock_setup_entry, patch(
"homeassistant.components.philips_js.async_unload_entry", return_value=True
):
yield mock_setup_entry
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
async def setup_notification(hass): async def setup_notification(hass):
"""Configure notification system.""" """Configure notification system."""

View file

@ -1,5 +1,5 @@
"""Test the Philips TV config flow.""" """Test the Philips TV config flow."""
from unittest.mock import ANY, patch from unittest.mock import ANY
from haphilipsjs import PairingFailure from haphilipsjs import PairingFailure
import pytest import pytest
@ -19,16 +19,7 @@ from . import (
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
@pytest.fixture(autouse=True, name="mock_setup_entry")
def mock_setup_entry_fixture():
"""Disable component setup."""
with patch(
"homeassistant.components.philips_js.async_setup_entry", return_value=True
) as mock_setup_entry, patch(
"homeassistant.components.philips_js.async_unload_entry", return_value=True
):
yield mock_setup_entry
@pytest.fixture @pytest.fixture

View file

@ -1,8 +1,9 @@
"""Provide common Renault fixtures.""" """Provide common Renault fixtures."""
from collections.abc import Generator
import contextlib import contextlib
from types import MappingProxyType from types import MappingProxyType
from typing import Any from typing import Any
from unittest.mock import patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from renault_api.kamereon import exceptions, schemas from renault_api.kamereon import exceptions, schemas
@ -18,6 +19,15 @@ from .const import MOCK_ACCOUNT_ID, MOCK_CONFIG, MOCK_VEHICLES
from tests.common import MockConfigEntry, load_fixture from tests.common import MockConfigEntry, load_fixture
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.renault.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
@pytest.fixture(name="vehicle_type", params=MOCK_VEHICLES.keys()) @pytest.fixture(name="vehicle_type", params=MOCK_VEHICLES.keys())
def get_vehicle_type(request: pytest.FixtureRequest) -> str: def get_vehicle_type(request: pytest.FixtureRequest) -> str:
"""Parametrize vehicle type.""" """Parametrize vehicle type."""

View file

@ -21,14 +21,7 @@ from .const import MOCK_CONFIG
from tests.common import load_fixture from tests.common import load_fixture
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
@pytest.fixture(autouse=True, name="mock_setup_entry")
def override_async_setup_entry() -> AsyncMock:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.renault.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
async def test_config_flow_single_account( async def test_config_flow_single_account(

View file

@ -1,7 +1,7 @@
"""Fixtures for Samsung TV.""" """Fixtures for Samsung TV."""
from __future__ import annotations from __future__ import annotations
from collections.abc import Awaitable, Callable from collections.abc import Awaitable, Callable, Generator
from datetime import datetime from datetime import datetime
from socket import AddressFamily from socket import AddressFamily
from typing import Any from typing import Any
@ -25,6 +25,15 @@ import homeassistant.util.dt as dt_util
from .const import SAMPLE_DEVICE_INFO_UE48JU6400, SAMPLE_DEVICE_INFO_WIFI from .const import SAMPLE_DEVICE_INFO_UE48JU6400, SAMPLE_DEVICE_INFO_WIFI
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.samsungtv.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
async def silent_ssdp_scanner(hass): async def silent_ssdp_scanner(hass):
"""Start SSDP component and get Scanner, prevent actual SSDP traffic.""" """Start SSDP component and get Scanner, prevent actual SSDP traffic."""

View file

@ -1,5 +1,4 @@
"""Tests for Samsung TV config flow.""" """Tests for Samsung TV config flow."""
from collections.abc import Generator
import socket import socket
from unittest.mock import ANY, AsyncMock, Mock, call, patch from unittest.mock import ANY, AsyncMock, Mock, call, patch
@ -216,14 +215,7 @@ DEVICEINFO_WEBSOCKET_NO_SSL = {
"timeout": TIMEOUT_WEBSOCKET, "timeout": TIMEOUT_WEBSOCKET,
} }
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
@pytest.fixture(autouse=True, name="mock_setup_entry")
def override_async_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.samsungtv.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
@pytest.mark.usefixtures("remote", "rest_api_failing") @pytest.mark.usefixtures("remote", "rest_api_failing")

View file

@ -1,7 +1,7 @@
"""Provide common SFR Box fixtures.""" """Provide common SFR Box fixtures."""
from collections.abc import Generator from collections.abc import Generator
import json import json
from unittest.mock import patch from unittest.mock import AsyncMock, patch
import pytest import pytest
from sfrbox_api.models import DslInfo, SystemInfo from sfrbox_api.models import DslInfo, SystemInfo
@ -14,6 +14,15 @@ from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry, load_fixture from tests.common import MockConfigEntry, load_fixture
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.sfr_box.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
@pytest.fixture(name="config_entry") @pytest.fixture(name="config_entry")
def get_config_entry(hass: HomeAssistant) -> ConfigEntry: def get_config_entry(hass: HomeAssistant) -> ConfigEntry:
"""Create and register mock config entry.""" """Create and register mock config entry."""

View file

@ -1,5 +1,4 @@
"""Test the SFR Box config flow.""" """Test the SFR Box config flow."""
from collections.abc import Generator
import json import json
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
@ -15,14 +14,7 @@ from homeassistant.core import HomeAssistant
from tests.common import load_fixture from tests.common import load_fixture
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
@pytest.fixture(autouse=True, name="mock_setup_entry")
def override_async_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.sfr_box.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
async def test_config_flow_skip_auth( async def test_config_flow_skip_auth(

View file

@ -2,7 +2,7 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Generator from collections.abc import Generator
from unittest.mock import MagicMock, create_autospec, patch from unittest.mock import AsyncMock, MagicMock, create_autospec, patch
from asyncsleepiq import ( from asyncsleepiq import (
Side, Side,
@ -40,6 +40,15 @@ SLEEPIQ_CONFIG = {
} }
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.sleepiq.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
@pytest.fixture @pytest.fixture
def mock_bed() -> MagicMock: def mock_bed() -> MagicMock:
"""Mock a SleepIQBed object with sleepers and lights.""" """Mock a SleepIQBed object with sleepers and lights."""

View file

@ -1,5 +1,4 @@
"""Tests for the SleepIQ config flow.""" """Tests for the SleepIQ config flow."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
from asyncsleepiq import SleepIQLoginException, SleepIQTimeoutException from asyncsleepiq import SleepIQLoginException, SleepIQTimeoutException
@ -12,14 +11,7 @@ from homeassistant.core import HomeAssistant
from .conftest import SLEEPIQ_CONFIG, setup_platform from .conftest import SLEEPIQ_CONFIG, setup_platform
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
@pytest.fixture(autouse=True, name="mock_setup_entry")
def override_async_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.sleepiq.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
async def test_import(hass: HomeAssistant) -> None: async def test_import(hass: HomeAssistant) -> None: