Skip to content

Instantly share code, notes, and snippets.

@vedant1811
Last active February 26, 2024 11:47
Show Gist options
  • Save vedant1811/06292da904132fb9434495063e5ef7e6 to your computer and use it in GitHub Desktop.
Save vedant1811/06292da904132fb9434495063e5ef7e6 to your computer and use it in GitHub Desktop.
Disable celery in django test.
# ...
# Set the class as TEST_RUNNER in settings.py
TEST_RUNNER = 'app.test.TestRunner'
# in myapp/app/test.py
from django.test.runner import DiscoverRunner
from django.conf import settings
from celery import current_app
class TestRunner(DiscoverRunner):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@staticmethod
def __disable_celery():
settings.CELERY_BROKER_URL = current_app.conf.CELERY_BROKER_URL = f'filesystem:///dev/null/'
settings.BROKER_TRANSPORT_OPTIONS = current_app.conf.BROKER_TRANSPORT_OPTIONS = {
'data_folder_in': '/tmp',
'data_folder_out': '/tmp',
'data_folder_processed': '/tmp',
}
def setup_test_environment(self, **kwargs):
TestRunner.__disable_celery()
super(TestRunner, self).setup_test_environment(**kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment