mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +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
|
import asyncio
|
||||||
from collections.abc import AsyncGenerator, Generator
|
from collections.abc import AsyncGenerator, Generator
|
||||||
|
from pathlib import Path
|
||||||
from random import getrandbits
|
from random import getrandbits
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
@ -39,13 +40,22 @@ def temp_dir_prefix() -> str:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@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."""
|
"""Mock the certificate temp directory."""
|
||||||
with patch(
|
mqtt_temp_dir = f"home-assistant-mqtt-{temp_dir_prefix}-{getrandbits(10):03x}"
|
||||||
# Patch temp dir name to avoid tests fail running in parallel
|
with (
|
||||||
"homeassistant.components.mqtt.util.TEMP_DIR_NAME",
|
patch(
|
||||||
f"home-assistant-mqtt-{temp_dir_prefix}-{getrandbits(10):03x}",
|
"homeassistant.components.mqtt.util.tempfile.gettempdir",
|
||||||
) as mocked_temp_dir:
|
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
|
yield mocked_temp_dir
|
||||||
|
|
||||||
|
|
||||||
|
@ -1034,6 +1034,7 @@ async def test_reloadable(
|
|||||||
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_temp_dir")
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("hass_config", "payload1", "state1", "payload2", "state2"),
|
("hass_config", "payload1", "state1", "payload2", "state2"),
|
||||||
[
|
[
|
||||||
|
@ -1409,6 +1409,7 @@ async def test_reloadable(
|
|||||||
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_temp_dir")
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"hass_config",
|
"hass_config",
|
||||||
[
|
[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user