Skip to content

Commit 8972e27

Browse files
authored
chore: Add macos executor for unit tests (#1334)
### Description - Run unit tests in CI also on `MacOS` to prevent OS-specific incompatible changes, for example: #1329 - Add time tolerance for the `test_emit_system_info_event` to minimize flakiness of the test.
1 parent f65f230 commit 8972e27

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

.github/workflows/run_code_checks.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
httpbin_url: ${{ secrets.APIFY_HTTPBIN_TOKEN && format('https://httpbin.apify.actor?token={0}', secrets.APIFY_HTTPBIN_TOKEN) || 'https://httpbin.org'}}
3737
with:
3838
python-versions: '["3.10", "3.11", "3.12", "3.13", "3.14"]'
39+
os: '["ubuntu-latest", "windows-latest", "macos-latest"]'
3940

4041
docs_check:
4142
name: Docs check

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)