diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_mongoengine.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/tests/test_mongoengine.py b/tests/test_mongoengine.py index 988c179..c0a019c 100644 --- a/tests/test_mongoengine.py +++ b/tests/test_mongoengine.py @@ -61,10 +61,20 @@ class MongoEngineTestCase(unittest.TestCase): db_name = os.environ.get('MONGO_DATABASE', 'factory_boy_test') db_host = os.environ.get('MONGO_HOST', 'localhost') db_port = int(os.environ.get('MONGO_PORT', '27017')) + MONGOD_TIMEOUT_MS = 100 @classmethod def setUpClass(cls): - cls.db = mongoengine.connect(cls.db_name, host=cls.db_host, port=cls.db_port) + from pymongo import read_preferences as mongo_rp + cls.db = mongoengine.connect( + db=cls.db_name, + host=cls.db_host, + port=cls.db_port, + # PyMongo>=2.1 requires an explicit read_preference. + read_preference=mongo_rp.ReadPreference.PRIMARY, + # PyMongo>=2.1 has a 20s timeout, use 100ms instead + serverselectiontimeoutms=cls.MONGOD_TIMEOUT_MS, + ) @classmethod def tearDownClass(cls): |