@@ -759,6 +759,7 @@ def test_list_databases(self):
759
759
for doc in helper_docs :
760
760
self .assertIs (type (doc ), dict )
761
761
client = rs_or_single_client (document_class = SON )
762
+ self .addCleanup (client .close )
762
763
for doc in client .list_databases ():
763
764
self .assertIs (type (doc ), dict )
764
765
@@ -979,6 +980,7 @@ def test_unix_socket(self):
979
980
uri = "mongodb://%s" % encoded_socket
980
981
# Confirm we can do operations via the socket.
981
982
client = rs_or_single_client (uri )
983
+ self .addCleanup (client .close )
982
984
client .pymongo_test .test .insert_one ({"dummy" : "object" })
983
985
dbs = client .list_database_names ()
984
986
self .assertTrue ("pymongo_test" in dbs )
@@ -1002,6 +1004,7 @@ def test_document_class(self):
1002
1004
self .assertFalse (isinstance (db .test .find_one (), SON ))
1003
1005
1004
1006
c = rs_or_single_client (document_class = SON )
1007
+ self .addCleanup (c .close )
1005
1008
db = c .pymongo_test
1006
1009
1007
1010
self .assertEqual (SON , c .codec_options .document_class )
@@ -1040,6 +1043,7 @@ def test_socket_timeout(self):
1040
1043
no_timeout = self .client
1041
1044
timeout_sec = 1
1042
1045
timeout = rs_or_single_client (socketTimeoutMS = 1000 * timeout_sec )
1046
+ self .addCleanup (timeout .close )
1043
1047
1044
1048
no_timeout .pymongo_test .drop_collection ("test" )
1045
1049
no_timeout .pymongo_test .test .insert_one ({"x" : 1 })
@@ -1095,6 +1099,7 @@ def test_tz_aware(self):
1095
1099
self .assertRaises (ValueError , MongoClient , tz_aware = "foo" )
1096
1100
1097
1101
aware = rs_or_single_client (tz_aware = True )
1102
+ self .addCleanup (aware .close )
1098
1103
naive = self .client
1099
1104
aware .pymongo_test .drop_collection ("test" )
1100
1105
@@ -1124,6 +1129,7 @@ def test_ipv6(self):
1124
1129
uri += "/?replicaSet=" + (client_context .replica_set_name or "" )
1125
1130
1126
1131
client = rs_or_single_client_noauth (uri )
1132
+ self .addCleanup (client .close )
1127
1133
client .pymongo_test .test .insert_one ({"dummy" : "object" })
1128
1134
client .pymongo_test_bernie .test .insert_one ({"dummy" : "object" })
1129
1135
@@ -1222,6 +1228,7 @@ def test_operation_failure(self):
1222
1228
# to avoid race conditions caused by replica set failover or idle
1223
1229
# socket reaping.
1224
1230
client = single_client ()
1231
+ self .addCleanup (client .close )
1225
1232
client .pymongo_test .test .find_one ()
1226
1233
pool = get_pool (client )
1227
1234
socket_count = len (pool .sockets )
@@ -1245,18 +1252,21 @@ def test_lazy_connect_w0(self):
1245
1252
self .addCleanup (client_context .client .drop_database , "test_lazy_connect_w0" )
1246
1253
1247
1254
client = rs_or_single_client (connect = False , w = 0 )
1255
+ self .addCleanup (client .close )
1248
1256
client .test_lazy_connect_w0 .test .insert_one ({})
1249
1257
wait_until (
1250
1258
lambda : client .test_lazy_connect_w0 .test .count_documents ({}) == 1 , "find one document"
1251
1259
)
1252
1260
1253
1261
client = rs_or_single_client (connect = False , w = 0 )
1262
+ self .addCleanup (client .close )
1254
1263
client .test_lazy_connect_w0 .test .update_one ({}, {"$set" : {"x" : 1 }})
1255
1264
wait_until (
1256
1265
lambda : client .test_lazy_connect_w0 .test .find_one ().get ("x" ) == 1 , "update one document"
1257
1266
)
1258
1267
1259
1268
client = rs_or_single_client (connect = False , w = 0 )
1269
+ self .addCleanup (client .close )
1260
1270
client .test_lazy_connect_w0 .test .delete_one ({})
1261
1271
wait_until (
1262
1272
lambda : client .test_lazy_connect_w0 .test .count_documents ({}) == 0 , "delete one document"
@@ -1267,6 +1277,7 @@ def test_exhaust_network_error(self):
1267
1277
# When doing an exhaust query, the socket stays checked out on success
1268
1278
# but must be checked in on error to avoid semaphore leaks.
1269
1279
client = rs_or_single_client (maxPoolSize = 1 , retryReads = False )
1280
+ self .addCleanup (client .close )
1270
1281
collection = client .pymongo_test .test
1271
1282
pool = get_pool (client )
1272
1283
pool ._check_interval_seconds = None # Never check.
0 commit comments