33import socket
44import sys
55from typing import Optional
6- from unittest .mock import patch
6+
7+ from mock .mock import patch
78
89# the functionality is available in 3.11.x but has a major issue before
910# 3.11.3. See https://github.com/redis/redis-py/issues/2633
2021from redis .utils import HIREDIS_AVAILABLE
2122from tests .conftest import get_protocol_version , skip_if_server_version_lt
2223
23- from .compat import aclosing , create_task , mock
24+ from .compat import aclosing
2425
2526
2627def with_timeout (t ):
@@ -733,7 +734,7 @@ async def loop_step():
733734 await messages .put (message )
734735 break
735736
736- task = asyncio .get_running_loop (). create_task (loop ())
737+ task = asyncio .create_task (loop ())
737738 # get the initial connect message
738739 async with async_timeout (1 ):
739740 message = await messages .get ()
@@ -782,7 +783,7 @@ def callback(message):
782783 messages = asyncio .Queue ()
783784 p = pubsub
784785 await self ._subscribe (p , foo = callback )
785- task = asyncio .get_running_loop (). create_task (p .run ())
786+ task = asyncio .create_task (p .run ())
786787 await r .publish ("foo" , "bar" )
787788 message = await messages .get ()
788789 task .cancel ()
@@ -805,8 +806,8 @@ def exception_handler_callback(e, pubsub) -> None:
805806 exceptions = asyncio .Queue ()
806807 p = pubsub
807808 await self ._subscribe (p , foo = lambda x : None )
808- with mock . patch .object (p , "get_message" , side_effect = Exception ("error" )):
809- task = asyncio .get_running_loop (). create_task (
809+ with patch .object (p , "get_message" , side_effect = Exception ("error" )):
810+ task = asyncio .create_task (
810811 p .run (exception_handler = exception_handler_callback )
811812 )
812813 e = await exceptions .get ()
@@ -823,7 +824,7 @@ def callback(message):
823824
824825 messages = asyncio .Queue ()
825826 p = pubsub
826- task = asyncio .get_running_loop (). create_task (p .run ())
827+ task = asyncio .create_task (p .run ())
827828 # wait until loop gets settled. Add a subscription
828829 await asyncio .sleep (0.1 )
829830 await p .subscribe (foo = callback )
@@ -867,7 +868,7 @@ async def mysetup(self, r, method):
867868 else :
868869 self .get_message = self .loop_step_listen
869870
870- self .task = create_task (self .loop ())
871+ self .task = asyncio . create_task (self .loop ())
871872 # get the initial connect message
872873 message = await self .messages .get ()
873874 assert message == {
@@ -903,7 +904,7 @@ async def test_reconnect_socket_error(self, r: redis.Redis, method):
903904 async with self .cond :
904905 assert self .state == 0
905906 self .state = 1
906- with mock . patch .object (self .pubsub .connection , "_parser" ) as m :
907+ with patch .object (self .pubsub .connection , "_parser" ) as m :
907908 m .read_response .side_effect = socket .error
908909 m .can_read_destructive .side_effect = socket .error
909910 # wait until task noticies the disconnect until we
0 commit comments