Last active
February 26, 2024 11:47
-
-
Save vedant1811/06292da904132fb9434495063e5ef7e6 to your computer and use it in GitHub Desktop.
Disable celery in django test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
# Set the class as TEST_RUNNER in settings.py | |
TEST_RUNNER = 'app.test.TestRunner' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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