The Python Oracle

Celery tasks not throwing exception in Django Tests

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Dreaming in Puzzles

--

Chapters
00:00 Celery Tasks Not Throwing Exception In Django Tests
00:47 Accepted Answer Score 16
01:04 Answer 2 Score 5
01:14 Answer 3 Score 0
01:27 Thank you

--

Full question
https://stackoverflow.com/questions/2702...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #django #testing #celery #celerytask

#avk47



ACCEPTED ANSWER

Score 16


Seems I additionally had to set CELERY_EAGER_PROPAGATES_EXCEPTIONS to True.

Celery >=5.3.1 it is CELERY_TASK_EAGER_PROPAGATES.




ANSWER 2

Score 5


Under celery 4.0, I had to use CELERY_TASK_EAGER_PROPAGATES




ANSWER 3

Score 0


@override_settings(task_always_eager=True, task_eager_propagates=True)
def test_my_task(self):
    pass

is what worked for me using Celery 5.

Documentation on config name changes: https://docs.celeryq.dev/en/stable/userguide/configuration.html