From 1144e23d8d96543050291cafdc858d8fc82cab24 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 3 Jul 2024 23:21:30 -0500 Subject: [PATCH] Fix blocking I/O in config tests (#121144) --- tests/test_config.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/test_config.py b/tests/test_config.py index ae6cbb3ba5e..e15dcf31726 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -7,6 +7,7 @@ import contextlib import copy import logging import os +from pathlib import Path from typing import Any from unittest import mock from unittest.mock import AsyncMock, MagicMock, Mock, patch @@ -412,11 +413,10 @@ async def test_ensure_config_exists_creates_config(hass: HomeAssistant) -> None: async def test_ensure_config_exists_uses_existing_config(hass: HomeAssistant) -> None: """Test that calling ensure_config_exists uses existing config.""" - create_file(YAML_PATH) + await hass.async_add_executor_job(create_file, YAML_PATH) await config_util.async_ensure_config_exists(hass) - with open(YAML_PATH, encoding="utf8") as fp: - content = fp.read() + content = await hass.async_add_executor_job(Path(YAML_PATH).read_text) # File created with create_file are empty assert content == "" @@ -424,12 +424,11 @@ async def test_ensure_config_exists_uses_existing_config(hass: HomeAssistant) -> async def test_ensure_existing_files_is_not_overwritten(hass: HomeAssistant) -> None: """Test that calling async_create_default_config does not overwrite existing files.""" - create_file(SECRET_PATH) + await hass.async_add_executor_job(create_file, SECRET_PATH) await config_util.async_create_default_config(hass) - with open(SECRET_PATH, encoding="utf8") as fp: - content = fp.read() + content = await hass.async_add_executor_job(Path(SECRET_PATH).read_text) # File created with create_file are empty assert content == ""