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.
This commit is contained in:
Teemu R. 2024-09-27 10:34:30 +02:00 committed by GitHub
parent 69c270055d
commit 8321fd08aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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(