From c59fc4e3c7a2ef7bb67476f7f3dd33d5771c0bd0 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 3 Jul 2024 23:08:53 -0500 Subject: [PATCH] Fix blocking I/O in media_extractor tests (#121139) --- tests/components/media_extractor/test_init.py | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/components/media_extractor/test_init.py b/tests/components/media_extractor/test_init.py index 9708e1c2ad6..bc80e063697 100644 --- a/tests/components/media_extractor/test_init.py +++ b/tests/components/media_extractor/test_init.py @@ -290,16 +290,19 @@ async def test_cookiefile_detection( cookies_dir = os.path.join(hass.config.config_dir, "media_extractor") cookies_file = os.path.join(cookies_dir, "cookies.txt") - if not os.path.exists(cookies_dir): - os.makedirs(cookies_dir) + def _write_cookies_file() -> None: + if not os.path.exists(cookies_dir): + os.makedirs(cookies_dir) - with open(cookies_file, "w+", encoding="utf-8") as f: - f.write( - """# Netscape HTTP Cookie File + with open(cookies_file, "w+", encoding="utf-8") as f: + f.write( + """# Netscape HTTP Cookie File - .youtube.com TRUE / TRUE 1701708706 GPS 1 - """ - ) + .youtube.com TRUE / TRUE 1701708706 GPS 1 + """ + ) + + await hass.async_add_executor_job(_write_cookies_file) await hass.services.async_call( DOMAIN, @@ -314,7 +317,7 @@ async def test_cookiefile_detection( assert "Media extractor loaded cookies file" in caplog.text - os.remove(cookies_file) + await hass.async_add_executor_job(os.remove, cookies_file) await hass.services.async_call( DOMAIN,