diff --git a/test/test_retryable_writes.py b/test/test_retryable_writes.py index c09cef7cc..42f09ed11 100644 --- a/test/test_retryable_writes.py +++ b/test/test_retryable_writes.py @@ -97,6 +97,8 @@ def create_test(scenario_def, test): error = None db = rs_or_single_client(**test['clientOptions']).pymongo_test + # Close the client explicitly to avoid having too many threads open. + self.addCleanup(db.client.close) try: result = run_operation(db.test, test) except (ConnectionFailure, OperationFailure) as exc: diff --git a/test/test_transactions.py b/test/test_transactions.py index 9e0df00ad..b77253eca 100644 --- a/test/test_transactions.py +++ b/test/test_transactions.py @@ -347,6 +347,8 @@ def create_test(scenario_def, test): # with ScenarioDict. client = rs_client(event_listeners=[listener], **dict(test['clientOptions'])) + # Close the client explicitly to avoid having too many threads open. + self.addCleanup(client.close) # Kill all sessions before and after each test to prevent an open # transaction (from a test failure) from blocking collection/database