Skip to content

Commit

Permalink
Use standard "entity_registry_enabled_by_default" fixture (#134962)
Browse files Browse the repository at this point in the history
  • Loading branch information
chemelli74 authored Jan 7, 2025
1 parent d155d93 commit 3a213b2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 33 deletions.
12 changes: 1 addition & 11 deletions tests/components/freebox/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Test helpers for Freebox."""

import json
from unittest.mock import AsyncMock, PropertyMock, patch
from unittest.mock import AsyncMock, patch

from freebox_api.exceptions import HttpRequestError
import pytest
Expand Down Expand Up @@ -36,16 +36,6 @@ def mock_path():
yield


@pytest.fixture(autouse=True)
def enable_all_entities():
"""Make sure all entities are enabled."""
with patch(
"homeassistant.helpers.entity.Entity.entity_registry_enabled_default",
PropertyMock(return_value=True),
):
yield


@pytest.fixture
def mock_device_registry_devices(
hass: HomeAssistant, device_registry: dr.DeviceRegistry
Expand Down
2 changes: 2 additions & 0 deletions tests/components/freebox/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest.mock import Mock

from freezegun.api import FrozenDateTimeFactory
import pytest

from homeassistant.components.binary_sensor import (
DOMAIN as BINARY_SENSOR_DOMAIN,
Expand Down Expand Up @@ -45,6 +46,7 @@ async def test_raid_array_degraded(
)


@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_home(
hass: HomeAssistant, freezer: FrozenDateTimeFactory, router: Mock
) -> None:
Expand Down
11 changes: 4 additions & 7 deletions tests/components/prusalink/test_binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Test Prusalink sensors."""

from unittest.mock import PropertyMock, patch
from unittest.mock import patch

import pytest

Expand All @@ -12,16 +12,13 @@
@pytest.fixture(autouse=True)
def setup_binary_sensor_platform_only():
"""Only setup sensor platform."""
with (
patch("homeassistant.components.prusalink.PLATFORMS", [Platform.BINARY_SENSOR]),
patch(
"homeassistant.helpers.entity.Entity.entity_registry_enabled_default",
PropertyMock(return_value=True),
),
with patch(
"homeassistant.components.prusalink.PLATFORMS", [Platform.BINARY_SENSOR]
):
yield


@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_binary_sensors_no_job(
hass: HomeAssistant, mock_config_entry, mock_api
) -> None:
Expand Down
13 changes: 5 additions & 8 deletions tests/components/prusalink/test_sensor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Test Prusalink sensors."""

from datetime import UTC, datetime
from unittest.mock import PropertyMock, patch
from unittest.mock import patch

import pytest

Expand All @@ -27,16 +27,11 @@
@pytest.fixture(autouse=True)
def setup_sensor_platform_only():
"""Only setup sensor platform."""
with (
patch("homeassistant.components.prusalink.PLATFORMS", [Platform.SENSOR]),
patch(
"homeassistant.helpers.entity.Entity.entity_registry_enabled_default",
PropertyMock(return_value=True),
),
):
with patch("homeassistant.components.prusalink.PLATFORMS", [Platform.SENSOR]):
yield


@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_sensors_no_job(hass: HomeAssistant, mock_config_entry, mock_api) -> None:
"""Test sensors while no job active."""
assert await async_setup_component(hass, "prusalink", {})
Expand Down Expand Up @@ -140,6 +135,7 @@ async def test_sensors_no_job(hass: HomeAssistant, mock_config_entry, mock_api)
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == REVOLUTIONS_PER_MINUTE


@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_sensors_idle_job_mk3(
hass: HomeAssistant,
mock_config_entry,
Expand Down Expand Up @@ -248,6 +244,7 @@ async def test_sensors_idle_job_mk3(
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == REVOLUTIONS_PER_MINUTE


@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_sensors_active_job(
hass: HomeAssistant,
mock_config_entry,
Expand Down
11 changes: 4 additions & 7 deletions tests/components/upnp/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from datetime import datetime
import socket
from typing import Any
from unittest.mock import AsyncMock, MagicMock, PropertyMock, create_autospec, patch
from unittest.mock import AsyncMock, MagicMock, create_autospec, patch
from urllib.parse import urlparse

from async_upnp_client.aiohttp import AiohttpNotifyServer
Expand Down Expand Up @@ -286,11 +286,8 @@ async def mock_config_entry(

# Load config_entry.
entry.add_to_hass(hass)
with patch(
"homeassistant.helpers.entity.Entity.entity_registry_enabled_default",
PropertyMock(return_value=True),
):
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()

await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()

return entry
2 changes: 2 additions & 0 deletions tests/components/upnp/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime, timedelta

from async_upnp_client.profiles.igd import IgdDevice, IgdState
import pytest

from homeassistant.components.upnp.const import DEFAULT_SCAN_INTERVAL
from homeassistant.core import HomeAssistant
Expand All @@ -11,6 +12,7 @@
from tests.common import MockConfigEntry, async_fire_time_changed


@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_upnp_sensors(
hass: HomeAssistant, mock_config_entry: MockConfigEntry
) -> None:
Expand Down

0 comments on commit 3a213b2

Please sign in to comment.