Skip to content

Commit fc0632f

Browse files
committed
Add test tolerance
1 parent 58c8140 commit fc0632f

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

tests/unit/events/test_local_event_manager.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,24 @@
22

33
import asyncio
44
from datetime import timedelta
5-
from functools import update_wrapper
65
from typing import Any
76
from unittest.mock import AsyncMock
87

9-
import pytest
10-
118
from crawlee.events import LocalEventManager
129
from crawlee.events._types import Event, EventSystemInfoData
1310

1411

15-
@pytest.fixture
16-
def listener() -> AsyncMock:
17-
async def async_listener(payload: Any) -> None:
18-
pass
19-
20-
al = AsyncMock()
21-
update_wrapper(al, async_listener)
22-
return al
12+
async def test_emit_system_info_event() -> None:
13+
mocked_listener = AsyncMock()
2314

15+
async def async_listener(payload: Any) -> None:
16+
mocked_listener(payload)
2417

25-
async def test_emit_system_info_event(listener: AsyncMock) -> None:
26-
async with LocalEventManager(system_info_interval=timedelta(milliseconds=50)) as event_manager:
27-
event_manager.on(event=Event.SYSTEM_INFO, listener=listener)
28-
await asyncio.sleep(0.2)
18+
system_info_interval = timedelta(milliseconds=50)
19+
test_tolerance_coefficient = 10
20+
async with LocalEventManager(system_info_interval=system_info_interval) as event_manager:
21+
event_manager.on(event=Event.SYSTEM_INFO, listener=async_listener)
22+
await asyncio.sleep(system_info_interval.total_seconds() * test_tolerance_coefficient)
2923

30-
assert listener.call_count >= 1
31-
assert isinstance(listener.call_args[0][0], EventSystemInfoData)
24+
assert mocked_listener.call_count >= 1
25+
assert isinstance(mocked_listener.call_args[0][0], EventSystemInfoData)

0 commit comments

Comments
 (0)