Skip to content

Commit b847449

Browse files
committed
Remove last vestiges of mock.mock
With the minimum Python version now being high enough to drop the usage of the external mock module, switch to unittest.mock everywhere. Switch ayncio test_credentials to AsyncMock.
1 parent 440465b commit b847449

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

dev_requirements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ build
22
build==1.2.2.post1 ; platform_python_implementation == "PyPy"
33
click==8.0.4
44
invoke==2.2.0
5-
mock
6-
mock==5.1.0 ; platform_python_implementation == "PyPy"
75
packaging>=20.4
86
packaging==24.2 ; platform_python_implementation == "PyPy"
97

tests/test_asyncio/test_credentials.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
from asyncio import Lock as AsyncLock
55
from asyncio import sleep as async_sleep
66
from typing import Optional, Tuple, Union
7+
from unittest.mock import AsyncMock, call
78

89
import pytest
910
import pytest_asyncio
1011
import redis
11-
from mock.mock import Mock, call
1212
from redis import AuthenticationError, DataError, RedisError, ResponseError
1313
from redis.asyncio import Connection, ConnectionPool, Redis
1414
from redis.asyncio.retry import Retry
@@ -340,10 +340,10 @@ class TestStreamingCredentialProvider:
340340
indirect=True,
341341
)
342342
async def test_async_re_auth_all_connections(self, credential_provider):
343-
mock_connection = Mock(spec=Connection)
343+
mock_connection = AsyncMock(spec=Connection)
344344
mock_connection.retry = Retry(NoBackoff(), 0)
345-
mock_another_connection = Mock(spec=Connection)
346-
mock_pool = Mock(spec=ConnectionPool)
345+
mock_another_connection = AsyncMock(spec=Connection)
346+
mock_pool = AsyncMock(spec=ConnectionPool)
347347
mock_pool.connection_kwargs = {
348348
"credential_provider": credential_provider,
349349
}
@@ -391,16 +391,16 @@ async def re_auth_callback(token):
391391
indirect=True,
392392
)
393393
async def test_async_re_auth_partial_connections(self, credential_provider):
394-
mock_connection = Mock(spec=Connection)
394+
mock_connection = AsyncMock(spec=Connection)
395395
mock_connection.retry = Retry(NoBackoff(), 3)
396-
mock_another_connection = Mock(spec=Connection)
396+
mock_another_connection = AsyncMock(spec=Connection)
397397
mock_another_connection.retry = Retry(NoBackoff(), 3)
398-
mock_failed_connection = Mock(spec=Connection)
398+
mock_failed_connection = AsyncMock(spec=Connection)
399399
mock_failed_connection.read_response.side_effect = ConnectionError(
400400
"Failed auth"
401401
)
402402
mock_failed_connection.retry = Retry(NoBackoff(), 3)
403-
mock_pool = Mock(spec=ConnectionPool)
403+
mock_pool = AsyncMock(spec=ConnectionPool)
404404
mock_pool.connection_kwargs = {
405405
"credential_provider": credential_provider,
406406
}
@@ -454,14 +454,14 @@ async def re_auth_callback(token):
454454
indirect=True,
455455
)
456456
async def test_re_auth_pub_sub_in_resp3(self, credential_provider):
457-
mock_pubsub_connection = Mock(spec=Connection)
457+
mock_pubsub_connection = AsyncMock(spec=Connection)
458458
mock_pubsub_connection.get_protocol.return_value = 3
459459
mock_pubsub_connection.credential_provider = credential_provider
460460
mock_pubsub_connection.retry = Retry(NoBackoff(), 3)
461-
mock_another_connection = Mock(spec=Connection)
461+
mock_another_connection = AsyncMock(spec=Connection)
462462
mock_another_connection.retry = Retry(NoBackoff(), 3)
463463

464-
mock_pool = Mock(spec=ConnectionPool)
464+
mock_pool = AsyncMock(spec=ConnectionPool)
465465
mock_pool.connection_kwargs = {
466466
"credential_provider": credential_provider,
467467
}
@@ -516,14 +516,14 @@ async def re_auth_callback(token):
516516
indirect=True,
517517
)
518518
async def test_do_not_re_auth_pub_sub_in_resp2(self, credential_provider):
519-
mock_pubsub_connection = Mock(spec=Connection)
519+
mock_pubsub_connection = AsyncMock(spec=Connection)
520520
mock_pubsub_connection.get_protocol.return_value = 2
521521
mock_pubsub_connection.credential_provider = credential_provider
522522
mock_pubsub_connection.retry = Retry(NoBackoff(), 3)
523-
mock_another_connection = Mock(spec=Connection)
523+
mock_another_connection = AsyncMock(spec=Connection)
524524
mock_another_connection.retry = Retry(NoBackoff(), 3)
525525

526-
mock_pool = Mock(spec=ConnectionPool)
526+
mock_pool = AsyncMock(spec=ConnectionPool)
527527
mock_pool.connection_kwargs = {
528528
"credential_provider": credential_provider,
529529
}
@@ -583,10 +583,10 @@ async def test_fails_on_token_renewal(self, credential_provider):
583583
RequestTokenErr,
584584
RequestTokenErr,
585585
]
586-
mock_connection = Mock(spec=Connection)
586+
mock_connection = AsyncMock(spec=Connection)
587587
mock_connection.retry = Retry(NoBackoff(), 0)
588-
mock_another_connection = Mock(spec=Connection)
589-
mock_pool = Mock(spec=ConnectionPool)
588+
mock_another_connection = AsyncMock(spec=Connection)
589+
mock_pool = AsyncMock(spec=ConnectionPool)
590590
mock_pool.connection_kwargs = {
591591
"credential_provider": credential_provider,
592592
}

tests/test_asyncio/test_multidb/test_healthcheck.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from unittest.mock import AsyncMock, Mock
2+
13
import pytest
2-
from mock.mock import AsyncMock, Mock
34

45
from redis.asyncio.multidb.database import Database
56
from redis.asyncio.multidb.healthcheck import (

tests/test_credentials.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import threading
55
from time import sleep
66
from typing import Optional, Tuple, Union
7+
from unittest.mock import Mock, call
78

89
import pytest
910
import redis
10-
from mock.mock import Mock, call
1111
from redis import AuthenticationError, DataError, Redis, ResponseError
1212
from redis.auth.err import RequestTokenErr
1313
from redis.backoff import NoBackoff

0 commit comments

Comments
 (0)