2026-08-01 11:04:44 +08:00
|
|
|
"""Shared pytest fixtures for the yunke-server test suite."""
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from app.config import get_settings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
|
def reset_settings_cache():
|
|
|
|
|
"""Ensure each test starts with a fresh Settings cache.
|
|
|
|
|
|
|
|
|
|
Tests that mutate env vars and call `get_settings()` must also clear the
|
|
|
|
|
`lru_cache` themselves; this fixture is a safety net that runs after every
|
|
|
|
|
test so a cached `Settings` from one test never leaks into the next.
|
|
|
|
|
"""
|
|
|
|
|
yield
|
|
|
|
|
get_settings.cache_clear()
|
2026-08-01 14:51:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
|
def _disable_request_throttle(monkeypatch):
|
|
|
|
|
"""Zero out the conservative request-pace settings for the test suite.
|
|
|
|
|
|
|
|
|
|
Production defaults (``request_min_interval=1.0``, ``request_jitter=0.8``)
|
|
|
|
|
would make every mocked request sleep ~1-1.8s and balloon the suite's
|
|
|
|
|
runtime. In tests we want the *behaviour* (header stealth, backoff, cap)
|
|
|
|
|
without the wall-clock cost, so we pin the throttle env vars to 0. The
|
|
|
|
|
defaults themselves are still asserted directly via ``Settings`` field
|
|
|
|
|
introspection in ``test_config.py``. The cache is cleared on either side
|
|
|
|
|
so the zeroed env is picked up the first time a test reads settings.
|
|
|
|
|
"""
|
|
|
|
|
get_settings.cache_clear()
|
|
|
|
|
monkeypatch.setenv("REQUEST_MIN_INTERVAL", "0")
|
|
|
|
|
monkeypatch.setenv("REQUEST_JITTER", "0")
|
|
|
|
|
yield
|
|
|
|
|
get_settings.cache_clear()
|