Skip to content

Commit

Permalink
Fix tests with latest pymongo/mongoengine.
Browse files Browse the repository at this point in the history
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``.
  • Loading branch information
rbarrois committed Apr 12, 2015
1 parent c77d97d commit ae5d46a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tests/test_mongoengine.py
Expand Up @@ -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):
Expand Down

0 comments on commit ae5d46a

Please sign in to comment.