1๐
โ
You got it half way there ๐ For tests, I usually just a global variable (settings parameter in Django case). or environment variable telling one should skip certain aspects of the application under the test. This only if there is no other way to community with the underlying code, like settings class variables or flags.
In settings โ create a separate settings file for running the tests:
SKIP_TASKS = True
Then:
from django.conf import settings
def save(self, *args, **kwargs):
if not settings.SKIP_TASKS:
celery_app.send_task('test.apps.action')
else:
pass
Or from command line with environment variables:
SKIP_TASKS=true python manage.py test
import os
def save(self, *args, **kwargs):
if not os.environ.get("SKIP_TASKS"):
celery_app.send_task('test.apps.action')
else:
pass
๐คMikko Ohtamaa
Source:stackexchange.com