mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Fix temp files of mqtt CI tests not cleaned up properly (#138741)
* Fix temp files of mqtt CI tests not cleaned up properly * Do not cleanup tempfiles, patch gettempdir only
This commit is contained in:
parent
0dc1151a25
commit
33df208296
@ -2,6 +2,7 @@
|
||||
|
||||
import asyncio
|
||||
from collections.abc import AsyncGenerator, Generator
|
||||
from pathlib import Path
|
||||
from random import getrandbits
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, patch
|
||||
@ -39,13 +40,22 @@ def temp_dir_prefix() -> str:
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_temp_dir(temp_dir_prefix: str) -> Generator[str]:
|
||||
async def mock_temp_dir(
|
||||
hass: HomeAssistant, tmp_path: Path, temp_dir_prefix: str
|
||||
) -> AsyncGenerator[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:
|
||||
mqtt_temp_dir = f"home-assistant-mqtt-{temp_dir_prefix}-{getrandbits(10):03x}"
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.mqtt.util.tempfile.gettempdir",
|
||||
return_value=tmp_path,
|
||||
),
|
||||
patch(
|
||||
# Patch temp dir name to avoid tests fail running in parallel
|
||||
"homeassistant.components.mqtt.util.TEMP_DIR_NAME",
|
||||
mqtt_temp_dir,
|
||||
) as mocked_temp_dir,
|
||||
):
|
||||
yield mocked_temp_dir
|
||||
|
||||
|
||||
|
@ -1034,6 +1034,7 @@ async def test_reloadable(
|
||||
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_temp_dir")
|
||||
@pytest.mark.parametrize(
|
||||
("hass_config", "payload1", "state1", "payload2", "state2"),
|
||||
[
|
||||
|
@ -1409,6 +1409,7 @@ async def test_reloadable(
|
||||
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_temp_dir")
|
||||
@pytest.mark.parametrize(
|
||||
"hass_config",
|
||||
[
|
||||
|
Loading…
x
Reference in New Issue
Block a user