From ae5d46af448fc33ef74eee99c5a3d686c8d26e72 Mon Sep 17 00:00:00 2001 From: Raphaƫl Barrois Date: Sun, 12 Apr 2015 12:14:29 +0200 Subject: Fix tests with latest pymongo/mongoengine. mongoengine>=0.9.0 and pymongo>=2.1 require extra parameters: - The server connection timeout was set too high - We have to define a ``read_preference``. --- tests/test_mongoengine.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'tests') 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): -- cgit v1.2.3