test(redis cache): re-enable Test_RedisScheme + not-installed test for redis-py 8.x#721
Closed
wbarnha wants to merge 1 commit into
Closed
test(redis cache): re-enable Test_RedisScheme + not-installed test for redis-py 8.x#721wbarnha wants to merge 1 commit into
wbarnha wants to merge 1 commit into
Conversation
Both were skipped "Needs fixing" and had drifted against redis-py 8.x and the current cache backend: * Test_RedisScheme referenced `redis.StrictRedis`/`aredis.RedisCluster` as the backend module's client types, which no longer exist there. Assert instead against the scheme->client-class map the backend actually builds (`_client_by_scheme`): single-node resolves to redis-py 8.x's concrete `redis.client.Redis`; cluster resolves to `redis.RedisCluster`. The single-node client is built for real (redis-py connects lazily) and its `connection_pool.connection_kwargs` are checked; the cluster class -- which would connect on construction -- is mocked like the existing `mocked_redis` fixture, while scheme selection and db-stripping run for real. * test_redis__aredis_is_not_installed now patches the `redis` module name the backend's on_start guard actually reads (`if redis is None`), so it raises ImproperlyConfigured without opening a socket. Only external redis client classes are mocked; the backend logic runs for real. NB: the backend imports `redis.asyncio as aredis` but never guards on it -- a possible latent bug left for a separate source-side change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #721 +/- ##
==========================================
+ Coverage 94.15% 94.19% +0.04%
==========================================
Files 104 104
Lines 11136 11136
Branches 1201 1201
==========================================
+ Hits 10485 10490 +5
+ Misses 550 547 -3
+ Partials 101 99 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
Author
|
Closing in favour of #724, which now contains this test rewrite plus the backend not-installed-guard source fix, as a single independent PR off Generated by Claude Code |
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.
Description
Re-enables three redis cache tests skipped "Needs fixing" that had drifted against redis-py 8.x and the current cache backend.
Test_RedisScheme::test_single_client/test_cluster_clientreferencedredis.StrictRedis/aredis.RedisClusteras attributes of the backend module — which no longer exist there. They now assert against the scheme→client-class map the backend actually builds (_client_by_scheme): single-node resolves to redis-py 8.x's concreteredis.client.Redis; cluster resolves toredis.RedisCluster. The single-node client is built for real (redis-py connects lazily) and itsconnection_pool.connection_kwargs(host/port/db) are checked; the cluster class — which connects on construction — is mocked exactly like the existingmocked_redisfixture, while scheme selection anddb-stripping run for real.test_single_clientis strictly stronger than the original.test_redis__aredis_is_not_installednow patches theredismodule name the backend'son_startguard actually reads (if redis is None), so it raisesImproperlyConfiguredwithout opening a socket (the old fixture patchedaredis, which the guard never checks — so it opened a real connection tolocalhost:6079).Only external redis client classes are mocked; the backend logic runs for real. Test-only change.
Latent source bug noticed (not fixed here)
The backend does
import redis.asyncio as aredisbut itson_startguard only checksif redis is None, neveraredis. So the "async redis not installed" path is effectively dead / guards the wrong name. Left for a separate source-side PR to keep this change test-only.Verification
tests/functional/web/test_cache.py→ 32 passed; flake8/black/isort clean. Produced under adversarial faithfulness review.🤖 Generated with Claude Code
Generated by Claude Code