I want to be able to do conditional connect() based on either I started django in testing mode or not.
in my settings.py I use mongoengine connect() method to connect to
While it is possible to do that, it is easier and common practice to have 2 settings files. One possible configuration could be:
You have 2 settings files, lsettings.py
that doesn't connect and settings.py
that does
from lsettings import *
mongodb.connect()
So, while locally testing you can:
python manage.py test --settings=lsettings
And it doesn't connect.
tl;dr: It is easier to manage configuration differences by having multiple configuration files that import each other conditionally rather than trying to have conditional parameters within the same settings file. YMMV.