fix(tests): check for RediSearch module availability in Redis tests (#6687)

This commit is contained in:
Ratish jain
2026-08-14 17:00:56 +05:30
committed by GitHub
parent a10c0cd030
commit ef6f51d977
2 changed files with 32 additions and 4 deletions
+16 -2
View File
@@ -249,9 +249,23 @@ REDIS_HOST = os.environ.get("REDIS_HOST", "localhost")
REDIS_PORT = int(os.environ.get("REDIS_PORT", "6379"))
def _redis_search_available(host, port, timeout=2):
"""RediSearch (the FT.* command family) is an optional module, not part of vanilla Redis."""
if not _tcp_reachable(host, port, timeout=timeout):
return False
try:
import redis
client = redis.Redis(host=host, port=port, socket_connect_timeout=timeout, socket_timeout=timeout)
modules = {m["name"].lower() for m in client.module_list()}
return "search" in modules
except Exception:
return False
@pytest.mark.skipif(
not _tcp_reachable(REDIS_HOST, REDIS_PORT),
reason=f"Redis not reachable at {REDIS_HOST}:{REDIS_PORT}",
not _redis_search_available(REDIS_HOST, REDIS_PORT),
reason=f"RediSearch module not available at {REDIS_HOST}:{REDIS_PORT} (requires Redis Stack, not vanilla Redis)",
)
class TestRedisThreshold:
def test_threshold_filtering(self):
@@ -239,9 +239,23 @@ REDIS_HOST = os.environ.get("REDIS_HOST", "localhost")
REDIS_PORT = int(os.environ.get("REDIS_PORT", "6379"))
def _redis_search_available(host, port, timeout=2):
"""RediSearch (the FT.* command family) is an optional module, not part of vanilla Redis."""
if not _tcp_reachable(host, port, timeout=timeout):
return False
try:
import redis
client = redis.Redis(host=host, port=port, socket_connect_timeout=timeout, socket_timeout=timeout)
modules = {m["name"].lower() for m in client.module_list()}
return "search" in modules
except Exception:
return False
@pytest.mark.skipif(
not _tcp_reachable(REDIS_HOST, REDIS_PORT),
reason=f"Redis not reachable at {REDIS_HOST}:{REDIS_PORT}",
not _redis_search_available(REDIS_HOST, REDIS_PORT),
reason=f"RediSearch module not available at {REDIS_HOST}:{REDIS_PORT} (requires Redis Stack, not vanilla Redis)",
)
class TestRedis:
"""Redis returns cosine distance [0,2]. Conversion: score = max(0, 1 - dist)."""