@@ -657,13 +657,15 @@ def failed(event: CommandFailedEvent) -> None:
657657 return
658658 assert event .failure ["code" ] == 91
659659 self .configure_fail_point_sync (command_args_inner )
660+ self .addCleanup (self .configure_fail_point_sync , {}, off = True )
660661 listener .failed_events .append (event )
661662
662663 listener .failed = failed
663664
664665 client = await self .async_rs_client (retryWrites = True , event_listeners = [listener ])
665666
666667 self .configure_fail_point_sync (command_args )
668+ self .addCleanup (self .configure_fail_point_sync , {}, off = True )
667669
668670 # Attempt an insertOne operation on any record for any database and collection.
669671 # Expect the insertOne to fail with a server error.
@@ -673,9 +675,6 @@ def failed(event: CommandFailedEvent) -> None:
673675 # Assert that the error code of the server error is 10107.
674676 assert exc .exception .errors ["code" ] == 10107 # type:ignore[call-overload]
675677
676- # Disable the fail point.
677- self .configure_fail_point_sync ({}, off = True )
678-
679678 async def test_02_drivers_return_the_correct_error_when_receiving_only_errors_with_NoWritesPerformed (
680679 self
681680 ) -> None :
@@ -711,13 +710,15 @@ def failed(event: CommandFailedEvent) -> None:
711710 # Configure the 10107 fail point command only if the the failed event is for the 91 error configured in step 2.
712711 assert event .failure ["code" ] == 91
713712 self .configure_fail_point_sync (command_args_inner )
713+ self .addCleanup (self .configure_fail_point_sync , {}, off = True )
714714 listener .failed_events .append (event )
715715
716716 listener .failed = failed
717717
718718 client = await self .async_rs_client (retryWrites = True , event_listeners = [listener ])
719719
720720 self .configure_fail_point_sync (command_args )
721+ self .addCleanup (self .configure_fail_point_sync , {}, off = True )
721722
722723 # Attempt an insertOne operation on any record for any database and collection.
723724 # Expect the insertOne to fail with a server error.
@@ -727,9 +728,6 @@ def failed(event: CommandFailedEvent) -> None:
727728 # Assert that the error code of the server error is 91.
728729 assert exc .exception .errors ["code" ] == 91 # type:ignore[call-overload]
729730
730- # Disable the fail point.
731- self .configure_fail_point_sync ({}, off = True )
732-
733731 async def test_03_drivers_return_the_correct_error_when_receiving_some_errors_with_NoWritesPerformed_and_some_without_NoWritesPerformed (
734732 self
735733 ) -> None :
@@ -766,13 +764,15 @@ def failed(event: CommandFailedEvent) -> None:
766764 return
767765 assert event .failure ["code" ] == 91
768766 self .configure_fail_point_sync (command_args_inner )
767+ self .addCleanup (self .configure_fail_point_sync , {}, off = True )
769768 listener .failed_events .append (event )
770769
771770 listener .failed = failed
772771
773772 client = await self .async_rs_client (retryWrites = True , event_listeners = [listener ])
774773
775774 self .configure_fail_point_sync (command_args )
775+ self .addCleanup (self .configure_fail_point_sync , {}, off = True )
776776
777777 # Attempt an insertOne operation on any record for any database and collection.
778778 # Expect the insertOne to fail with a server error.
@@ -784,9 +784,6 @@ def failed(event: CommandFailedEvent) -> None:
784784 # Assert that the error does not contain the error label `NoWritesPerformed`.
785785 assert "NoWritesPerformed" not in exc .exception .errors ["errorLabels" ]
786786
787- # Disable the fail point.
788- self .configure_fail_point_sync ({}, off = True )
789-
790787
791788if __name__ == "__main__" :
792789 unittest .main ()
0 commit comments