diff --git a/packages/pytest-home-assistant/pyproject.toml b/packages/pytest-home-assistant/pyproject.toml index 55bb8d3ef2fa..863927717843 100644 --- a/packages/pytest-home-assistant/pyproject.toml +++ b/packages/pytest-home-assistant/pyproject.toml @@ -17,7 +17,6 @@ authors = [ # Dependency pins are synchronized by script.gen_requirements_all. dependencies = [ "homeassistant", - "aiohasupervisor==0.7.0", "bleak-retry-connector==4.7.1", "freezegun==1.5.5", "paho-mqtt==2.1.0", @@ -37,6 +36,7 @@ pytest_homeassistant = "pytest_homeassistant.bootstrap" [project.optional-dependencies] bluetooth = [ + "aiohasupervisor==0.7.0", "aiousbwatcher==1.1.2", "bluetooth-adapters==2.4.0", "bluetooth-auto-recovery==1.6.4", diff --git a/packages/pytest-home-assistant/pytest_homeassistant/components/hassio/__init__.py b/packages/pytest-home-assistant/pytest_homeassistant/components/hassio/__init__.py deleted file mode 100644 index e5669f777d2b..000000000000 --- a/packages/pytest-home-assistant/pytest_homeassistant/components/hassio/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -"""Tests for Hass.io component.""" - -SUPERVISOR_TOKEN = "123456" diff --git a/packages/pytest-home-assistant/pytest_homeassistant/plugins.py b/packages/pytest-home-assistant/pytest_homeassistant/plugins.py index 563264fe75b3..77db03261fab 100644 --- a/packages/pytest-home-assistant/pytest_homeassistant/plugins.py +++ b/packages/pytest-home-assistant/pytest_homeassistant/plugins.py @@ -709,6 +709,22 @@ def hass_config_dir() -> str: return get_test_config_dir() +@pytest.fixture +def entity_registry_enabled_by_default() -> Generator[None]: + """Test fixture that ensures all entities are enabled in the registry.""" + with ( + patch( + "homeassistant.helpers.entity.Entity.entity_registry_enabled_default", + return_value=True, + ), + patch( + "homeassistant.components.device_tracker.config_entry.ScannerEntity.entity_registry_enabled_default", + return_value=True, + ), + ): + yield + + @pytest.fixture def custom_integrations_enabled() -> bool: """Control custom integration loading.""" @@ -2274,39 +2290,6 @@ def mock_bleak_scanner_start() -> Generator[MagicMock]: yield mock_bleak_scanner_start -@pytest.fixture -def hassio_env( - supervisor_is_connected: AsyncMock, supervisor_root_info: AsyncMock -) -> Generator[None]: - """Fixture to inject hassio env.""" - from aiohasupervisor import SupervisorError # noqa: PLC0415 - - from .components.hassio import SUPERVISOR_TOKEN # noqa: PLC0415 - - supervisor_root_info.side_effect = SupervisorError() - with ( - patch.dict(os.environ, {"SUPERVISOR": "127.0.0.1"}), - patch.dict(os.environ, {"SUPERVISOR_TOKEN": SUPERVISOR_TOKEN}), - ): - yield - - -@pytest.fixture -async def hassio_stubs( - hassio_env: None, - hass: HomeAssistant, - hass_client: ClientSessionGenerator, - aioclient_mock: AiohttpClientMocker, - supervisor_client: AsyncMock, - ingress_panels: AsyncMock, -) -> None: - """Create mock hassio http client.""" - with patch( - "homeassistant.components.hassio.coordinator.SupervisorIssuesCoordinator.async_refresh", - ): - await async_setup_component(hass, "hassio", {}) - - @pytest.fixture def integration_frame_path() -> str: """Return the path to the integration frame. diff --git a/packages/pytest-home-assistant/tests/standalone/integration_tests/test_plugin.py b/packages/pytest-home-assistant/tests/standalone/integration_tests/test_plugin.py index 55a4a6659e6f..7a42613155d8 100644 --- a/packages/pytest-home-assistant/tests/standalone/integration_tests/test_plugin.py +++ b/packages/pytest-home-assistant/tests/standalone/integration_tests/test_plugin.py @@ -11,6 +11,7 @@ from homeassistant import loader from homeassistant.components.recorder import Recorder from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er +from homeassistant.helpers.entity import Entity from homeassistant.helpers.http import HomeAssistantView from homeassistant.setup import async_setup_component from pytest_homeassistant import _paths @@ -156,3 +157,11 @@ def test_historical_recorder_schema(schema: str) -> None: """Historical schema helpers must not import Core's test tree.""" module = import_module(get_schema_module_path(schema)) assert module.Base.metadata.tables + + +@pytest.mark.usefixtures("entity_registry_enabled_by_default") +def test_entity_registry_enabled_by_default() -> None: + """Registry fixtures enable entities that are disabled by default.""" + entity = Entity() + entity._attr_entity_registry_enabled_default = False + assert entity.entity_registry_enabled_default diff --git a/tests/components/conftest.py b/tests/components/conftest.py index 3a88b761945e..6a503539584e 100644 --- a/tests/components/conftest.py +++ b/tests/components/conftest.py @@ -6,6 +6,7 @@ from functools import lru_cache from importlib.util import find_spec import inspect from ipaddress import IPv4Address, IPv4Network +import os from pathlib import Path import re import string @@ -54,6 +55,8 @@ from aiohasupervisor.store import StoreClient from aiohasupervisor.supervisor import SupervisorManagementClient import probatio import pytest +from pytest_homeassistant.test_util.aiohttp import AiohttpClientMocker +from pytest_homeassistant.typing import ClientSessionGenerator from homeassistant import components, loader from homeassistant.components import repairs @@ -87,6 +90,7 @@ from homeassistant.exceptions import HomeAssistantError, Unauthorized from homeassistant.helpers import issue_registry as ir from homeassistant.helpers.translation import async_get_translations from homeassistant.helpers.typing import VolSchemaType +from homeassistant.setup import async_setup_component from homeassistant.util import yaml as yaml_util from tests.common import QualityScaleStatus, get_quality_scale @@ -125,22 +129,6 @@ def prevent_io() -> Generator[None]: yield -@pytest.fixture -def entity_registry_enabled_by_default() -> Generator[None]: - """Test fixture that ensures all entities are enabled in the registry.""" - with ( - patch( - "homeassistant.helpers.entity.Entity.entity_registry_enabled_default", - return_value=True, - ), - patch( - "homeassistant.components.device_tracker.config_entry.ScannerEntity.entity_registry_enabled_default", - return_value=True, - ), - ): - yield - - # TTS test fixtures @pytest.fixture(name="mock_tts_get_cache_files") def mock_tts_get_cache_files_fixture() -> Generator[MagicMock]: @@ -858,6 +846,39 @@ def supervisor_client() -> Generator[AsyncMock]: yield supervisor_client +@pytest.fixture +def hassio_env( + supervisor_is_connected: AsyncMock, supervisor_root_info: AsyncMock +) -> Generator[None]: + """Fixture to inject hassio env.""" + from aiohasupervisor import SupervisorError # noqa: PLC0415 + + from .hassio import SUPERVISOR_TOKEN # noqa: PLC0415 + + supervisor_root_info.side_effect = SupervisorError() + with ( + patch.dict(os.environ, {"SUPERVISOR": "127.0.0.1"}), + patch.dict(os.environ, {"SUPERVISOR_TOKEN": SUPERVISOR_TOKEN}), + ): + yield + + +@pytest.fixture +async def hassio_stubs( + hassio_env: None, + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + aioclient_mock: AiohttpClientMocker, + supervisor_client: AsyncMock, + ingress_panels: AsyncMock, +) -> None: + """Create mock hassio http client.""" + with patch( + "homeassistant.components.hassio.coordinator.SupervisorIssuesCoordinator.async_refresh", + ): + await async_setup_component(hass, "hassio", {}) + + def _validate_translation_placeholders( full_key: str, translation: str, diff --git a/tests/components/hassio/__init__.py b/tests/components/hassio/__init__.py index de7d279c095d..46ee77a3a5f5 100644 --- a/tests/components/hassio/__init__.py +++ b/tests/components/hassio/__init__.py @@ -1,3 +1,3 @@ -"""Compatibility imports for the Home Assistant pytest helpers.""" +"""Tests for the Supervisor integration.""" -from pytest_homeassistant.components.hassio import SUPERVISOR_TOKEN as SUPERVISOR_TOKEN +SUPERVISOR_TOKEN = "123456"