-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconftest.py
More file actions
47 lines (36 loc) · 1.43 KB
/
Copy pathconftest.py
File metadata and controls
47 lines (36 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Pytest configuration.
The test suite imports modules as top-level packages (e.g. `from services...`).
Depending on pytest's import mode, the DevMesh project root may not be present
on `sys.path`, causing intermittent `ModuleNotFoundError` during collection.
This file ensures the `devmesh/` directory is always on `sys.path` for tests.
"""
from __future__ import annotations
import sys
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parent
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
# Compatibility: some versions of the `websockets` package installed via OS
# packages don't expose `websockets.exceptions` as an attribute on the top
# module, but the code/tests reference it.
try:
import websockets # type: ignore
import websockets.exceptions as _ws_exceptions # type: ignore
websockets.exceptions = _ws_exceptions # type: ignore[attr-defined]
except Exception:
pass
@pytest.fixture(autouse=True)
def _reset_rate_limiter() -> None:
"""
Make tests deterministic by clearing shared rate-limiter state.
The production code uses a global rate limiter singleton; without resetting,
earlier tests can consume tokens and cause later websocket tests to fail.
"""
try:
from rate_limit import get_rate_limiter
get_rate_limiter().reset()
except Exception:
# If rate limiting isn't available for some reason, don't block tests.
pass