Fix blocking process call in process tests (#121104)

Discovered by ruff in https://github.com/home-assistant/core/pull/120799
This commit is contained in:
J. Nick Koston 2024-07-03 13:26:03 -07:00 committed by GitHub
parent 291f309c0e
commit 7958c0825e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,21 +1,26 @@
"""Test process util.""" """Test process util."""
from functools import partial
import os import os
import subprocess import subprocess
import pytest import pytest
from homeassistant.core import HomeAssistant
from homeassistant.util import process from homeassistant.util import process
async def test_kill_process() -> None: async def test_kill_process(hass: HomeAssistant) -> None:
"""Test killing a process.""" """Test killing a process."""
sleeper = subprocess.Popen( # noqa: S602 # shell by design sleeper = await hass.async_add_executor_job(
partial( # noqa: S604 # shell by design
subprocess.Popen,
"sleep 1000", "sleep 1000",
shell=True, shell=True,
stdout=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
) )
)
pid = sleeper.pid pid = sleeper.pid
assert os.kill(pid, 0) is None assert os.kill(pid, 0) is None