From b05f9ef587a318a6df3a288701d2386b838d45c2 Mon Sep 17 00:00:00 2001 From: Balloob Bot Date: Thu, 24 Sep 2026 02:07:41 -0400 Subject: [PATCH] Combine nested async with statements in timeout tests (#183026) Co-authored-by: Paulus Schoutsen Co-authored-by: Claude Opus 5 (1M context) --- tests/util/test_timeout.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tests/util/test_timeout.py b/tests/util/test_timeout.py index dc416662431b..c3d2b9381d44 100644 --- a/tests/util/test_timeout.py +++ b/tests/util/test_timeout.py @@ -122,13 +122,13 @@ async def test_mix_global_timeout_freeze_and_zone_freeze_other_zone_inside_execu with timeout.freeze("not_recorder"): time.sleep(0.3) - with pytest.raises(TimeoutError): # noqa: PT012 - async with timeout.async_timeout(0.1): - async with ( - timeout.async_timeout(0.2, zone_name="recorder"), - timeout.async_timeout(0.2, zone_name="not_recorder"), - ): - await hass.async_add_executor_job(_some_sync_work) + with pytest.raises(TimeoutError): + async with ( + timeout.async_timeout(0.1), + timeout.async_timeout(0.2, zone_name="recorder"), + timeout.async_timeout(0.2, zone_name="not_recorder"), + ): + await hass.async_add_executor_job(_some_sync_work) async def test_mix_global_timeout_freeze_and_zone_freeze_executor_2nd_outside_zone( @@ -304,20 +304,24 @@ async def test_multiple_zone_timeout() -> None: """Test a simple zone timeout.""" timeout = TimeoutManager() - with pytest.raises(TimeoutError): # noqa: PT012 - async with timeout.async_timeout(0.1, "test"): - async with timeout.async_timeout(0.5, "test"): - await asyncio.sleep(0.3) + with pytest.raises(TimeoutError): + async with ( + timeout.async_timeout(0.1, "test"), + timeout.async_timeout(0.5, "test"), + ): + await asyncio.sleep(0.3) async def test_different_zone_timeout() -> None: """Test a simple zone timeout.""" timeout = TimeoutManager() - with pytest.raises(TimeoutError): # noqa: PT012 - async with timeout.async_timeout(0.1, "test"): - async with timeout.async_timeout(0.5, "other"): - await asyncio.sleep(0.3) + with pytest.raises(TimeoutError): + async with ( + timeout.async_timeout(0.1, "test"), + timeout.async_timeout(0.5, "other"), + ): + await asyncio.sleep(0.3) async def test_simple_zone_timeout_freeze() -> None: