@@ -935,25 +935,29 @@ def assertEqualCommand(self, expected, actual, msg=None):
935935 def assertEqualReply (self , expected , actual , msg = None ):
936936 self .assertEqual (sanitize_reply (expected ), sanitize_reply (actual ), msg )
937937
938+ @staticmethod
939+ async def configure_fail_point (client , command_args ):
940+ cmd = {"configureFailPoint" : "failCommand" }
941+ cmd .update (command_args )
942+ try :
943+ await client .admin .command (cmd )
944+ return
945+ except pymongo .errors .ConnectionFailure :
946+ # Workaround PyPy bug described in PYTHON-5011.
947+ if not _IS_SYNC and "PyPy" in sys .version :
948+ await client .admin .command (cmd )
949+ return
950+ raise
951+
938952 @asynccontextmanager
939953 async def fail_point (self , command_args ):
940- cmd_on = SON ([("configureFailPoint" , "failCommand" )])
941- cmd_on .update (command_args )
942- await async_client_context .client .admin .command (cmd_on )
954+ name = command_args .get ("configureFailPoint" , "failCommand" )
955+ await self .configure_fail_point (async_client_context .client , command_args )
943956 try :
944957 yield
945958 finally :
946- try :
947- await async_client_context .client .admin .command (
948- "configureFailPoint" , cmd_on ["configureFailPoint" ], mode = "off"
949- )
950- except pymongo .errors .ConnectionFailure :
951- # Workaround PyPy bug described in PYTHON-5011.
952- if not _IS_SYNC and "PyPy" in sys .version :
953- await async_client_context .client .admin .command (
954- "configureFailPoint" , cmd_on ["configureFailPoint" ], mode = "off"
955- )
956- raise
959+ cmd_off = {"configureFailPoint" : name , "mode" : "off" }
960+ await self .configure_fail_point (async_client_context .client , cmd_off )
957961
958962 @contextmanager
959963 def fork (
0 commit comments