[codex] Stub optional clients for lightweight backend unit tests#7935
Open
tianmind-studio wants to merge 3 commits into
Open
[codex] Stub optional clients for lightweight backend unit tests#7935tianmind-studio wants to merge 3 commits into
tianmind-studio wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
conftest.pythat installs smallprometheus_client,redis, andcachetoolsstubs only when the real packages are unavailable.Counter,Gauge,Histogram,REGISTRY,generate_latest,CONTENT_TYPE_LATEST, labels, metric increments/sets, timers, and_value.get().Redis,ConnectionError,exceptions,get,set,delete,expire,ttl, counters,pipeline, and simple script eval fallback.cachetools.TTLCachesurface used byutils.byokduring module import.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 passedpython -m pytest backend\tests\unit\test_firmware_pagination.py --collect-only -q --tb=short->37 tests collectedpython -m pytest backend\tests\unit\test_firmware_pagination.py -q --tb=short->37 passedpython -m pytest backend\tests\unit\test_dg_start_guard.py --collect-only -q --tb=short->2 tests collectedpython -m pytest backend\tests\unit\test_dg_start_guard.py -q --tb=short->2 passedpython -m pytest backend\tests\unit\test_streaming_deepgram_backoff.py --collect-only -q --tb=short->82 tests collectedpython -m pytest backend\tests\unit\test_streaming_deepgram_backoff.py -q --tb=short->82 passedpython -m pytest backend\tests\unit\test_dg_start_guard.py backend\tests\unit\test_streaming_deepgram_backoff.py -q --tb=short->84 passedpython -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 passedpython -m pytest backend\tests\unit\test_daily_summary_regenerate.py --collect-only -q --tb=short->2 tests collectedpython -m pytest backend\tests\unit\test_daily_summary_regenerate.py -q --tb=short->2 passedpython -m black --line-length 120 --skip-string-normalization backend\tests\unit\conftest.pypython -m py_compile backend\tests\unit\conftest.pygit diff --checkscripts\pre-commitNote
This PR intentionally covers missing package fallbacks only. It does not try to repair every cross-test
sys.modulesmutation 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.