Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions kasa/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import asyncio
import warnings
from unittest.mock import MagicMock, patch

Expand Down Expand Up @@ -96,6 +97,18 @@ def pytest_collection_modifyitems(config, items):
item.add_marker(requires_dummy)


@pytest.fixture(autouse=True, scope="session")
def asyncio_sleep_fixture(): # noqa: PT004
"""Patch sleep to prevent tests actually waiting."""
orig_asyncio_sleep = asyncio.sleep

async def _asyncio_sleep(*_, **__):
await orig_asyncio_sleep(0)

with patch("asyncio.sleep", side_effect=_asyncio_sleep):
yield


# allow mocks to be awaited
# https://stackoverflow.com/questions/51394411/python-object-magicmock-cant-be-used-in-await-expression/51399767#51399767

Expand Down
3 changes: 0 additions & 3 deletions kasa/tests/test_klapprotocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ 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):
Expand Down Expand Up @@ -140,7 +138,6 @@ async def test_protocol_retry_recoverable_error(
"post",
side_effect=aiohttp.ClientOSError("foo"),
)
mocker.patch("asyncio.sleep")

config = DeviceConfig(host)
with pytest.raises(KasaException):
Expand Down