Ensure random temp dir is used during MQTT CI tests (#137221)

This commit is contained in:
Jan Bouwhuis 2025-02-03 17:06:02 +01:00 committed by GitHub
parent a5eda3faf1
commit 30af9057d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 9 deletions

View File

@ -38,7 +38,7 @@ def temp_dir_prefix() -> str:
return "test"
@pytest.fixture
@pytest.fixture(autouse=True)
def mock_temp_dir(temp_dir_prefix: str) -> Generator[str]:
"""Mock the certificate temp directory."""
with patch(

View File

@ -4,7 +4,6 @@ import asyncio
from collections.abc import Callable
from datetime import timedelta
from pathlib import Path
from random import getrandbits
import shutil
import tempfile
from unittest.mock import MagicMock, patch
@ -199,7 +198,6 @@ async def test_reading_non_exitisting_certificate_file() -> None:
)
@pytest.mark.parametrize("temp_dir_prefix", "unknown")
async def test_return_default_get_file_path(
hass: HomeAssistant, mock_temp_dir: str
) -> None:
@ -211,12 +209,8 @@ async def test_return_default_get_file_path(
and mqtt.util.get_file_path("some_option", "mydefault") == "mydefault"
)
with patch(
"homeassistant.components.mqtt.util.TEMP_DIR_NAME",
f"home-assistant-mqtt-other-{getrandbits(10):03x}",
) as temp_dir_name:
tempdir = Path(tempfile.gettempdir()) / temp_dir_name
assert await hass.async_add_executor_job(_get_file_path, tempdir)
temp_dir = Path(tempfile.gettempdir()) / mock_temp_dir
assert await hass.async_add_executor_job(_get_file_path, temp_dir)
async def test_waiting_for_client_not_loaded(