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."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
import pytest
@ -10,14 +9,7 @@ from homeassistant.components.NEW_DOMAIN.const import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@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
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
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."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
from unittest.mock import AsyncMock
import pytest
@ -11,14 +10,7 @@ from homeassistant.data_entry_flow import FlowResultType
from tests.common import MockConfigEntry
@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
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
@pytest.mark.parametrize("platform", ("sensor",))

View file

@ -1,5 +1,5 @@
"""Test configuration for Nibe Heat Pump."""
from collections.abc import AsyncIterator, Iterable
from collections.abc import AsyncIterator, Generator, Iterable
from contextlib import ExitStack
from typing import Any
from unittest.mock import AsyncMock, Mock, patch
@ -10,6 +10,15 @@ from nibe.exceptions import ReadException
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")
async def fixture_mock_connection_constructor():
"""Make sure we have a dummy connection."""

View file

@ -1,5 +1,5 @@
"""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.exceptions import (
@ -32,13 +32,7 @@ MOCK_FLOW_MODBUS_USERDATA = {
}
@pytest.fixture(autouse=True, name="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
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
async def _get_connection_form(

View file

@ -1,5 +1,6 @@
"""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
import pytest
@ -14,6 +15,15 @@ from .const import MOCK_OWPROXY_DEVICES
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())
def get_device_id(request: pytest.FixtureRequest) -> str:
"""Parametrize device id."""

View file

@ -1,5 +1,4 @@
"""Tests for 1-Wire config flow."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
from pyownet import protocol
@ -19,14 +18,7 @@ from homeassistant.helpers.config_validation import ensure_list
from .const import MOCK_OWPROXY_DEVICES
@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
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
@pytest.fixture

View file

@ -1,5 +1,6 @@
"""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
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
@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)
async def setup_notification(hass):
"""Configure notification system."""

View file

@ -1,5 +1,5 @@
"""Test the Philips TV config flow."""
from unittest.mock import ANY, patch
from unittest.mock import ANY
from haphilipsjs import PairingFailure
import pytest
@ -19,16 +19,7 @@ from . import (
from tests.common import MockConfigEntry
@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
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
@pytest.fixture

View file

@ -1,8 +1,9 @@
"""Provide common Renault fixtures."""
from collections.abc import Generator
import contextlib
from types import MappingProxyType
from typing import Any
from unittest.mock import patch
from unittest.mock import AsyncMock, patch
import pytest
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
@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())
def get_vehicle_type(request: pytest.FixtureRequest) -> str:
"""Parametrize vehicle type."""

View file

@ -21,14 +21,7 @@ from .const import MOCK_CONFIG
from tests.common import load_fixture
@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
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
async def test_config_flow_single_account(

View file

@ -1,7 +1,7 @@
"""Fixtures for Samsung TV."""
from __future__ import annotations
from collections.abc import Awaitable, Callable
from collections.abc import Awaitable, Callable, Generator
from datetime import datetime
from socket import AddressFamily
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
@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)
async def silent_ssdp_scanner(hass):
"""Start SSDP component and get Scanner, prevent actual SSDP traffic."""

View file

@ -1,5 +1,4 @@
"""Tests for Samsung TV config flow."""
from collections.abc import Generator
import socket
from unittest.mock import ANY, AsyncMock, Mock, call, patch
@ -216,14 +215,7 @@ DEVICEINFO_WEBSOCKET_NO_SSL = {
"timeout": TIMEOUT_WEBSOCKET,
}
@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
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
@pytest.mark.usefixtures("remote", "rest_api_failing")

View file

@ -1,7 +1,7 @@
"""Provide common SFR Box fixtures."""
from collections.abc import Generator
import json
from unittest.mock import patch
from unittest.mock import AsyncMock, patch
import pytest
from sfrbox_api.models import DslInfo, SystemInfo
@ -14,6 +14,15 @@ from homeassistant.core import HomeAssistant
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")
def get_config_entry(hass: HomeAssistant) -> ConfigEntry:
"""Create and register mock config entry."""

View file

@ -1,5 +1,4 @@
"""Test the SFR Box config flow."""
from collections.abc import Generator
import json
from unittest.mock import AsyncMock, patch
@ -15,14 +14,7 @@ from homeassistant.core import HomeAssistant
from tests.common import load_fixture
@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
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
async def test_config_flow_skip_auth(

View file

@ -2,7 +2,7 @@
from __future__ import annotations
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 (
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
def mock_bed() -> MagicMock:
"""Mock a SleepIQBed object with sleepers and lights."""

View file

@ -1,5 +1,4 @@
"""Tests for the SleepIQ config flow."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
from asyncsleepiq import SleepIQLoginException, SleepIQTimeoutException
@ -12,14 +11,7 @@ from homeassistant.core import HomeAssistant
from .conftest import SLEEPIQ_CONFIG, setup_platform
@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
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
async def test_import(hass: HomeAssistant) -> None: