core/tests/components/mqtt/conftest.py

39 lines
1.1 KiB
Python

"""Test fixtures for mqtt component."""
from collections.abc import Generator
from random import getrandbits
from unittest.mock import AsyncMock, patch
import pytest
from tests.components.light.conftest import mock_light_profiles # noqa: F401
@pytest.fixture(autouse=True)
def patch_hass_config(mock_hass_config: None) -> None:
"""Patch configuration.yaml."""
@pytest.fixture
def temp_dir_prefix() -> str:
"""Set an alternate temp dir prefix."""
return "test"
@pytest.fixture
def mock_temp_dir(temp_dir_prefix: str) -> Generator[None, None, str]:
"""Mock the certificate temp directory."""
with patch(
# Patch temp dir name to avoid tests fail running in parallel
"homeassistant.components.mqtt.util.TEMP_DIR_NAME",
f"home-assistant-mqtt-{temp_dir_prefix}-{getrandbits(10):03x}",
) as mocked_temp_dir:
yield mocked_temp_dir
@pytest.fixture
def tag_mock() -> Generator[AsyncMock, None, None]:
"""Fixture to mock tag."""
with patch("homeassistant.components.tag.async_scan_tag") as mock_tag:
yield mock_tag