Skip to content

[codex] Stub optional clients for lightweight backend unit tests#7935

Open
tianmind-studio wants to merge 3 commits into
BasedHardware:mainfrom
tianmind-studio:codex/windows-prometheus-test-stub
Open

[codex] Stub optional clients for lightweight backend unit tests#7935
tianmind-studio wants to merge 3 commits into
BasedHardware:mainfrom
tianmind-studio:codex/windows-prometheus-test-stub

Conversation

@tianmind-studio

@tianmind-studio tianmind-studio commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a unit-test conftest.py that installs small prometheus_client, redis, and cachetools stubs only when the real packages are unavailable.
  • Cover the Prometheus surfaces used by existing backend unit tests: Counter, Gauge, Histogram, REGISTRY, generate_latest, CONTENT_TYPE_LATEST, labels, metric increments/sets, timers, and _value.get().
  • Cover the Redis import-time/client surfaces needed by lightweight unit tests: Redis, ConnectionError, exceptions, get, set, delete, expire, ttl, counters, pipeline, and simple script eval fallback.
  • Cover the narrow cachetools.TTLCache surface used by utils.byok during module import.
  • Leave CI and full backend environments unchanged because each stub is skipped when the real package is installed.

Why

On this Windows lightweight backend venv, several unit tests could not even collect because they import modules that initialize optional infrastructure clients or caches at module import time. These tests do not require a real Prometheus client, Redis SDK, Redis service, or cachetools package to validate their behavior, so missing optional packages blocked unrelated assertions.

Before this change:

  • python -m pytest backend\tests\unit\test_async_tasks.py --collect-only -q --tb=short -> ModuleNotFoundError: No module named 'prometheus_client'
  • python -m pytest backend\tests\unit\test_pusher_circuit_breaker.py --collect-only -q --tb=short -> ModuleNotFoundError: No module named 'prometheus_client'
  • python -m pytest backend\tests\unit\test_firmware_pagination.py --collect-only -q --tb=short -> ModuleNotFoundError: No module named 'redis'
  • python -m pytest backend\tests\unit\test_dg_start_guard.py --collect-only -q --tb=short -> ModuleNotFoundError: No module named 'cachetools'
  • python -m pytest backend\tests\unit\test_streaming_deepgram_backoff.py --collect-only -q --tb=short -> ModuleNotFoundError: No module named 'cachetools'

Validation

  • python -m pytest backend\tests\unit\test_async_tasks.py backend\tests\unit\test_pusher_circuit_breaker.py -q --tb=short -> 78 passed
  • python -m pytest backend\tests\unit\test_firmware_pagination.py --collect-only -q --tb=short -> 37 tests collected
  • python -m pytest backend\tests\unit\test_firmware_pagination.py -q --tb=short -> 37 passed
  • python -m pytest backend\tests\unit\test_dg_start_guard.py --collect-only -q --tb=short -> 2 tests collected
  • python -m pytest backend\tests\unit\test_dg_start_guard.py -q --tb=short -> 2 passed
  • python -m pytest backend\tests\unit\test_streaming_deepgram_backoff.py --collect-only -q --tb=short -> 82 tests collected
  • python -m pytest backend\tests\unit\test_streaming_deepgram_backoff.py -q --tb=short -> 82 passed
  • python -m pytest backend\tests\unit\test_dg_start_guard.py backend\tests\unit\test_streaming_deepgram_backoff.py -q --tb=short -> 84 passed
  • python -m pytest backend\tests\unit\test_async_tasks.py backend\tests\unit\test_pusher_circuit_breaker.py backend\tests\unit\test_firmware_pagination.py backend\tests\unit\test_dg_start_guard.py backend\tests\unit\test_streaming_deepgram_backoff.py -q --tb=short -> 199 passed
  • python -m pytest backend\tests\unit\test_daily_summary_regenerate.py --collect-only -q --tb=short -> 2 tests collected
  • python -m pytest backend\tests\unit\test_daily_summary_regenerate.py -q --tb=short -> 2 passed
  • python -m black --line-length 120 --skip-string-normalization backend\tests\unit\conftest.py
  • python -m py_compile backend\tests\unit\conftest.py
  • git diff --check
  • scripts\pre-commit

Note

This PR intentionally covers missing package fallbacks only. It does not try to repair every cross-test sys.modules mutation where another test leaves an empty package or module behind; those order-isolation fixes are handled in the specific test files that create or consume those stubs.

@tianmind-studio tianmind-studio changed the title [codex] Stub Prometheus for lightweight backend unit tests [codex] Stub optional clients for lightweight backend unit tests Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant