I have the following code at the end of my Django settings:
if not TESTING:
# Don't use local settings for tests, so that tests are always reproducible.
try:
from .local_settings import *
except ImportError:
pass
local_settings.py contains all the external dependencies URLs used by my Django application, such as database server URL, email server URL and external APIs URLs. Currently the only external dependency my test suite uses is a local test database; everything else is mocked.
However, now I'd like to add some tests that validate responses from the external APIs I use, so that I can detect quickly when an external API changes without prior notice. I'd like to add a --external-deps command line argument to "./manage.py test" and only run tests that depend on external APIs if this flag is enabled.
I know that I can process arguments passed to that command by overriding the add_arguments() method of the DiscoverRunner class, as described in Django manage.py : Is it possible to pass command line argument (for unit testing) , but my conditional Django settings loading are run before that, so the following won't work:
if not TESTING or TEST_EXTERNAL_DEPS:
# Don't use local settings for tests, so that tests are always reproducible.
try:
from .local_settings import *
except ImportError:
pass
Is there a way to achieve what I want?