@@ -313,17 +313,25 @@ def record_a_read(self, address):
313
313
314
314
class TestCommandAndReadPreference (TestReplicaSetClientBase ):
315
315
316
- def setUp (self ):
317
- super (TestCommandAndReadPreference , self ).setUp ()
318
- self .c = ReadPrefTester (
316
+ @classmethod
317
+ def setUpClass (cls ):
318
+ super (TestCommandAndReadPreference , cls ).setUpClass ()
319
+ cls .c = ReadPrefTester (
319
320
'%s:%s' % (host , port ),
320
- replicaSet = self .name ,
321
+ replicaSet = cls .name ,
321
322
# Ignore round trip times, to test ReadPreference modes only.
322
323
localThresholdMS = 1000 * 1000 )
323
324
if client_context .auth_enabled :
324
- self .c .admin .authenticate (db_user , db_pwd )
325
- self .client_version = Version .from_client (self .c )
326
- self .addCleanup (self .c .drop_database , 'pymongo_test' )
325
+ cls .c .admin .authenticate (db_user , db_pwd )
326
+ cls .client_version = Version .from_client (cls .c )
327
+ # mapReduce and group fail with no collection
328
+ coll = cls .c .pymongo_test .get_collection (
329
+ 'test' , write_concern = WriteConcern (w = cls .w ))
330
+ coll .insert_one ({})
331
+
332
+ @classmethod
333
+ def tearDownClass (cls ):
334
+ cls .c .drop_database ('pymongo_test' )
327
335
328
336
def executed_on_which_server (self , client , fn , * args , ** kwargs ):
329
337
"""Execute fn(*args, **kwargs) and return the Server instance used."""
@@ -397,24 +405,11 @@ def test_group(self):
397
405
{'a' : 1 }, {}, {}, 'function() { }' )
398
406
399
407
def test_map_reduce (self ):
400
- # mapreduce fails if no collection
401
- coll = self .c .pymongo_test .test .with_options (
402
- write_concern = WriteConcern (w = self .w ))
403
- coll .insert_one ({})
404
-
405
- self ._test_coll_helper (False , self .c .pymongo_test .test , 'map_reduce' ,
406
- 'function() { }' , 'function() { }' , 'mr_out' )
407
-
408
408
self ._test_coll_helper (False , self .c .pymongo_test .test , 'map_reduce' ,
409
409
'function() { }' , 'function() { }' ,
410
410
{'inline' : 1 })
411
411
412
412
def test_inline_map_reduce (self ):
413
- # mapreduce fails if no collection
414
- coll = self .c .pymongo_test .test .with_options (
415
- write_concern = WriteConcern (w = self .w ))
416
- coll .insert_one ({})
417
-
418
413
self ._test_coll_helper (True , self .c .pymongo_test .test ,
419
414
'inline_map_reduce' ,
420
415
'function() { }' , 'function() { }' )
0 commit comments