Skip to content

Commit 769d776

Browse files
authored
test_stopwatch uses freezegun (#4138)
Use freezegun instead of `time.sleep`.
1 parent b07e5b9 commit 769d776

File tree

6 files changed

+155
-127
lines changed

6 files changed

+155
-127
lines changed

.github/actions/setup-environment/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ runs:
122122
123123
"testing")
124124
# Install main dependencies + testing group, excluding interactive and dev
125-
uv sync --no-group interactive --no-group dev --group testing
125+
uv sync --no-group interactive --no-group dev --group testing --all-packages
126126
;;
127127
128128
# used in the mettascope tests where we run code to generate outputs but do not run tests

metta/setup/components/uv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def check_installed(self) -> bool:
2727
sys.exit(1)
2828

2929
def install(self, non_interactive: bool = False, force: bool = False) -> None:
30-
cmd = ["uv", "sync"]
30+
cmd = ["uv", "sync", "--all-packages"]
3131
cmd.extend(["--force-reinstall", "--no-cache"] if force else [])
3232
env = os.environ.copy()
3333
env["METTAGRID_FORCE_NIM_BUILD"] = "1"

packages/mettagrid/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ dependencies = [
3030
]
3131

3232
[dependency-groups]
33-
dev = ["pytest>=8.3.3", "pytest-benchmark>=5.1.0", "pytest-xdist>=3.8.0"]
33+
testing = ["pytest>=8.3.3", "pytest-benchmark>=5.1.0", "pytest-xdist>=3.8.0", "freezegun>=1.5.0"]
34+
dev = [{ include-group = "testing" }]
3435

3536
[tool.bazel]
3637
# Bazel build configuration

packages/mettagrid/python/src/mettagrid/profiling/stopwatch.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import functools
24
import inspect
35
import logging
@@ -81,7 +83,7 @@ def _capture_caller_info(extra_skip_frames: int = 0) -> Tuple[str, int]:
8183
del frame
8284

8385

84-
def with_timer(timer: "Stopwatch", name: str, log_level: int | None = None):
86+
def with_timer(timer: Stopwatch, name: str, log_level: int | None = None):
8587
"""Decorator that wraps function execution in a timer context."""
8688

8789
def decorator(func: F) -> F:
@@ -288,7 +290,7 @@ def time(
288290
display_name = name or self.GLOBAL_TIMER_NAME
289291
self.logger.log(log_level, f"{display_name} took {elapsed:.3f}s")
290292

291-
def __call__(self, name: str | None = None, log_level: int | None = None) -> ContextManager["Stopwatch"]:
293+
def __call__(self, name: str | None = None, log_level: int | None = None) -> ContextManager[Stopwatch]:
292294
"""Make Stopwatch callable to return context manager.
293295
294296
Args:

0 commit comments

Comments
 (0)