Skip to content

Commit c7c2567

Browse files
committed
Clean up read preference tests
1 parent 06b32a0 commit c7c2567

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

test/test_read_preferences.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -313,17 +313,25 @@ def record_a_read(self, address):
313313

314314
class TestCommandAndReadPreference(TestReplicaSetClientBase):
315315

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(
319320
'%s:%s' % (host, port),
320-
replicaSet=self.name,
321+
replicaSet=cls.name,
321322
# Ignore round trip times, to test ReadPreference modes only.
322323
localThresholdMS=1000*1000)
323324
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')
327335

328336
def executed_on_which_server(self, client, fn, *args, **kwargs):
329337
"""Execute fn(*args, **kwargs) and return the Server instance used."""
@@ -397,24 +405,11 @@ def test_group(self):
397405
{'a': 1}, {}, {}, 'function() { }')
398406

399407
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-
408408
self._test_coll_helper(False, self.c.pymongo_test.test, 'map_reduce',
409409
'function() { }', 'function() { }',
410410
{'inline': 1})
411411

412412
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-
418413
self._test_coll_helper(True, self.c.pymongo_test.test,
419414
'inline_map_reduce',
420415
'function() { }', 'function() { }')

0 commit comments

Comments
 (0)