Skip to content

Commit 5ba56fe

Browse files
committed
Add conftest.py for the wall clock timer tests
For now, we include one fixture that we will use to mock the `datetime` class imported in the wall clock timer definition, so we can control the current time in the tests (and set the default to the UNIX epoch to make it easier to read times in the tests). We don't use time-machine for 2 reasons: 1. We will also need to use async-solipsism and time-machine also mocks the monotonic timer, sometimes conflicting with async-solipsism. 2. We want to tell only when sleep was called within the wall clock timer module, not in the tests for example. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent fd57d3f commit 5ba56fe

File tree

1 file changed

+21
-0
lines changed
  • tests/timeseries/_resampling/wall_clock_timer

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# License: MIT
2+
# Copyright © 2025 Frequenz Energy-as-a-Service GmbH
3+
4+
"""Fixtures for wall clock timer tests."""
5+
6+
from collections.abc import Iterator
7+
from datetime import datetime
8+
from unittest.mock import MagicMock, patch
9+
10+
import pytest
11+
from frequenz.core.datetime import UNIX_EPOCH
12+
13+
14+
@pytest.fixture
15+
def datetime_mock() -> Iterator[MagicMock]:
16+
"""Mock the datetime class in the target module and set now to the UNIX epoch."""
17+
dt_symbol = "frequenz.sdk.timeseries._resampling._wall_clock_timer.datetime"
18+
dt_mock = MagicMock(name="datetime_mock", wraps=datetime, spec_set=datetime)
19+
dt_mock.now.return_value = UNIX_EPOCH
20+
with patch(dt_symbol, new=dt_mock):
21+
yield dt_mock

0 commit comments

Comments
 (0)