19
19
import pytest
20
20
import redis
21
21
import redis .asyncio
22
+ from fakeredis .aioredis import FakeRedis
22
23
from redis .exceptions import ConnectionError as redis_ConnectionError
23
24
from redis .exceptions import WatchError
24
25
@@ -359,7 +360,7 @@ def test_response_error(self):
359
360
def test_watch_error_sync (self ):
360
361
def redis_operations ():
361
362
with pytest .raises (WatchError ):
362
- redis_client = redis . Redis ()
363
+ redis_client = fakeredis . FakeStrictRedis ()
363
364
pipe = redis_client .pipeline (transaction = True )
364
365
pipe .watch ("a" )
365
366
redis_client .set ("a" , "bad" ) # This will cause the WatchError
@@ -389,7 +390,7 @@ class TestRedisAsync(TestBase, IsolatedAsyncioTestCase):
389
390
def setUp (self ):
390
391
super ().setUp ()
391
392
self .instrumentor = RedisInstrumentor ()
392
- self .client = redis . asyncio . Redis ()
393
+ self .client = FakeRedis ()
393
394
394
395
async def _redis_pipeline_operations (self , client ):
395
396
with pytest .raises (WatchError ):
@@ -415,8 +416,7 @@ def response_hook(span, conn, args):
415
416
self .instrumentor .instrument (
416
417
tracer_provider = self .tracer_provider , response_hook = response_hook
417
418
)
418
- redis_client = redis .asyncio .Redis ()
419
-
419
+ redis_client = FakeRedis ()
420
420
await self ._redis_pipeline_operations (redis_client )
421
421
422
422
# 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):
439
439
self .instrumentor .instrument_connection (
440
440
tracer_provider = self .tracer_provider , client = self .client
441
441
)
442
- redis_client = redis . asyncio . Redis ()
442
+ redis_client = FakeRedis ()
443
443
await self ._redis_pipeline_operations (redis_client )
444
444
445
445
spans = self .memory_exporter .get_finished_spans ()
@@ -519,7 +519,7 @@ def response_hook(span, conn, args):
519
519
self .assertEqual (span .attributes .get (request_attr ), "SET" )
520
520
self .assertEqual (span .attributes .get (response_attr ), True )
521
521
# fresh client should not record any spans
522
- fresh_client = redis . asyncio . Redis ()
522
+ fresh_client = FakeRedis ()
523
523
self .memory_exporter .clear ()
524
524
await fresh_client .set ("key" , "value" )
525
525
self .assert_span_count (0 )
@@ -532,7 +532,7 @@ def response_hook(span, conn, args):
532
532
class TestRedisInstance (TestBase ):
533
533
def setUp (self ):
534
534
super ().setUp ()
535
- self .client = redis . Redis ()
535
+ self .client = fakeredis . FakeStrictRedis ()
536
536
RedisInstrumentor ().instrument_connection (
537
537
client = self .client , tracer_provider = self .tracer_provider
538
538
)
@@ -568,7 +568,7 @@ def redis_operations(client):
568
568
pipe .execute ()
569
569
570
570
def test_watch_error_sync_only_client (self ):
571
- redis_client = redis . Redis ()
571
+ redis_client = fakeredis . FakeStrictRedis ()
572
572
573
573
self .redis_operations (redis_client )
574
574
0 commit comments