11from unittest import mock
2- from asyncio import Future
32
43import pytest
54from redis import asyncio as aioredis
@@ -11,7 +10,7 @@ class TestRedisClient:
1110
1211 @pytest.fixture
1312 def async_mock(self):
14- yield mock.MagicMock(return_value=Future() )
13+ yield mock.AsyncMock( )
1514
1615 def test_should_create_client_and_populate_defaults(self):
1716 # given / when
@@ -58,7 +57,7 @@ class TestRedisClient:
5857 # given
5958 RedisClient.open_redis_client()
6059 RedisClient.redis_client.ping = async_mock
61- async_mock.return_value.set_result( True)
60+ async_mock.return_value = True
6261
6362 # when
6463 result = await RedisClient.ping()
@@ -85,7 +84,7 @@ class TestRedisClient:
8584 # given
8685 RedisClient.open_redis_client()
8786 RedisClient.redis_client.set = async_mock
88- async_mock.return_value.set_result( "OK")
87+ async_mock.return_value = "OK"
8988
9089 # when
9190 result = await RedisClient.set("key", "value")
@@ -110,7 +109,7 @@ class TestRedisClient:
110109 # given
111110 RedisClient.open_redis_client()
112111 RedisClient.redis_client.rpush = async_mock
113- async_mock.return_value.set_result(10)
112+ async_mock.return_value = 10
114113
115114 # when
116115 result = await RedisClient.rpush("key", "value")
@@ -135,7 +134,7 @@ class TestRedisClient:
135134 # given
136135 RedisClient.open_redis_client()
137136 RedisClient.redis_client.exists = async_mock
138- async_mock.return_value.set_result( True)
137+ async_mock.return_value = True
139138
140139 # when
141140 result = await RedisClient.exists("key")
@@ -160,7 +159,7 @@ class TestRedisClient:
160159 # given
161160 RedisClient.open_redis_client()
162161 RedisClient.redis_client.get = async_mock
163- async_mock.return_value.set_result( "value")
162+ async_mock.return_value = "value"
164163
165164 # when
166165 result = await RedisClient.get("key")
@@ -185,7 +184,7 @@ class TestRedisClient:
185184 # given
186185 RedisClient.open_redis_client()
187186 RedisClient.redis_client.lrange = async_mock
188- async_mock.return_value.set_result( ["value", "value2"])
187+ async_mock.return_value = ["value", "value2"]
189188
190189 # when
191190 result = await RedisClient.lrange("key", 1, -1)
0 commit comments