From 8321fd08aae54a4f7e462ef5e6b3cef7aae0fbd6 Mon Sep 17 00:00:00 2001 From: "Teemu R." Date: Fri, 27 Sep 2024 10:34:30 +0200 Subject: [PATCH] Mock asyncio.sleep for klapprotocol tests (#1130) Speeds up tests in `test_klapprotocol.py` from 26s to 2s when there's no sleep between the retries. --- kasa/tests/test_klapprotocol.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kasa/tests/test_klapprotocol.py b/kasa/tests/test_klapprotocol.py index 24d5df5d..4862235a 100644 --- a/kasa/tests/test_klapprotocol.py +++ b/kasa/tests/test_klapprotocol.py @@ -67,6 +67,7 @@ async def test_protocol_retries_via_client_session( host = "127.0.0.1" conn = mocker.patch.object(aiohttp.ClientSession, "post", side_effect=error) mocker.patch.object(protocol_class, "BACKOFF_SECONDS_AFTER_TIMEOUT", 0) + mocker.patch("asyncio.sleep") config = DeviceConfig(host) with pytest.raises(KasaException): @@ -139,6 +140,8 @@ async def test_protocol_retry_recoverable_error( "post", side_effect=aiohttp.ClientOSError("foo"), ) + mocker.patch("asyncio.sleep") + config = DeviceConfig(host) with pytest.raises(KasaException): await protocol_class(transport=transport_class(config=config)).query(