Cleanup runtime warnings in async unit tests (#137308)

This commit is contained in:
epenet 2025-02-04 11:44:17 +01:00 committed by GitHub
parent 650351a7f3
commit 09cea6ce96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -134,8 +134,10 @@ async def test_create_eager_task_312(hass: HomeAssistant) -> None:
async def test_create_eager_task_from_thread(hass: HomeAssistant) -> None:
"""Test we report trying to create an eager task from a thread."""
coro = asyncio.sleep(0)
def create_task():
hasync.create_eager_task(asyncio.sleep(0))
hasync.create_eager_task(coro)
with pytest.raises(
RuntimeError,
@ -145,14 +147,19 @@ async def test_create_eager_task_from_thread(hass: HomeAssistant) -> None:
):
await hass.async_add_executor_job(create_task)
# Avoid `RuntimeWarning: coroutine 'sleep' was never awaited`
await coro
async def test_create_eager_task_from_thread_in_integration(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test we report trying to create an eager task from a thread."""
coro = asyncio.sleep(0)
def create_task():
hasync.create_eager_task(asyncio.sleep(0))
hasync.create_eager_task(coro)
frames = extract_stack_to_frame(
[
@ -200,6 +207,9 @@ async def test_create_eager_task_from_thread_in_integration(
"self.light.is_on"
) in caplog.text
# Avoid `RuntimeWarning: coroutine 'sleep' was never awaited`
await coro
async def test_get_scheduled_timer_handles(hass: HomeAssistant) -> None:
"""Test get_scheduled_timer_handles returns all scheduled timer handles."""