[Solved]-How to disable celery tasks while testing on django


Usually the "good method" imply doing Mocks.

So you’ll return example response from the site.

You can check on class declaration debug state and if True replace the class by the corresponding Mock


You can patch the Task delay function

   patch("celery.app.task.Task.delay", return_value=1)
   patch("celery.app.task.Task.apply_async", return_value=1)

If you are using pytest, you can add this in conftest.py:

def mock_celery_delay(mocker):
    mocker.patch("celery.app.task.Task.delay", return_value=1)
    mocker.patch("celery.app.task.Task.apply_async", return_value=1)

Leave a comment