1919import pytest
2020import redis
2121import redis .asyncio
22+ from fakeredis .aioredis import FakeRedis
2223from redis .exceptions import ConnectionError as redis_ConnectionError
2324from redis .exceptions import WatchError
2425
@@ -359,7 +360,7 @@ def test_response_error(self):
359360 def test_watch_error_sync (self ):
360361 def redis_operations ():
361362 with pytest .raises (WatchError ):
362- redis_client = redis . Redis ()
363+ redis_client = fakeredis . FakeStrictRedis ()
363364 pipe = redis_client .pipeline (transaction = True )
364365 pipe .watch ("a" )
365366 redis_client .set ("a" , "bad" ) # This will cause the WatchError
@@ -389,7 +390,7 @@ class TestRedisAsync(TestBase, IsolatedAsyncioTestCase):
389390 def setUp (self ):
390391 super ().setUp ()
391392 self .instrumentor = RedisInstrumentor ()
392- self .client = redis . asyncio . Redis ()
393+ self .client = FakeRedis ()
393394
394395 async def _redis_pipeline_operations (self , client ):
395396 with pytest .raises (WatchError ):
@@ -415,8 +416,7 @@ def response_hook(span, conn, args):
415416 self .instrumentor .instrument (
416417 tracer_provider = self .tracer_provider , response_hook = response_hook
417418 )
418- redis_client = redis .asyncio .Redis ()
419-
419+ redis_client = FakeRedis ()
420420 await self ._redis_pipeline_operations (redis_client )
421421
422422 # there should be 3 tests, we start watch operation and have 2 set operation on same key
@@ -439,7 +439,7 @@ async def test_watch_error_async_only_client(self):
439439 self .instrumentor .instrument_connection (
440440 tracer_provider = self .tracer_provider , client = self .client
441441 )
442- redis_client = redis . asyncio . Redis ()
442+ redis_client = FakeRedis ()
443443 await self ._redis_pipeline_operations (redis_client )
444444
445445 spans = self .memory_exporter .get_finished_spans ()
@@ -519,7 +519,7 @@ def response_hook(span, conn, args):
519519 self .assertEqual (span .attributes .get (request_attr ), "SET" )
520520 self .assertEqual (span .attributes .get (response_attr ), True )
521521 # fresh client should not record any spans
522- fresh_client = redis . asyncio . Redis ()
522+ fresh_client = FakeRedis ()
523523 self .memory_exporter .clear ()
524524 await fresh_client .set ("key" , "value" )
525525 self .assert_span_count (0 )
@@ -532,7 +532,7 @@ def response_hook(span, conn, args):
532532class TestRedisInstance (TestBase ):
533533 def setUp (self ):
534534 super ().setUp ()
535- self .client = redis . Redis ()
535+ self .client = fakeredis . FakeStrictRedis ()
536536 RedisInstrumentor ().instrument_connection (
537537 client = self .client , tracer_provider = self .tracer_provider
538538 )
@@ -568,7 +568,7 @@ def redis_operations(client):
568568 pipe .execute ()
569569
570570 def test_watch_error_sync_only_client (self ):
571- redis_client = redis . Redis ()
571+ redis_client = fakeredis . FakeStrictRedis ()
572572
573573 self .redis_operations (redis_client )
574574
0 commit comments