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 my database but the problem is that I don’t want to do that if I ran manage.py test
Is there any way I can check if settings.py is being imported from tests or not, some flag maybe.
something like
if not IN_TESTS:
connect()
I’m solving this with a custom test runner. Here is an example I based my solution off of: https://github.com/xintron/django-mongorunner/blob/master/mongorunner/testrunner.py
This has the advantage of providing a fresh database for each of your unit tests.