Before moving to Dramatiq I used to use Celery. And when it came to unit testing the first thing I added to my code was:
:::python CELERY_ALWAYS_EAGER = True CELERY_EAGER_PROPAGATES_EXCEPTIONS = True
At the time I thought this was the best way. But after a lot of trial and error (and mainly because of Dramatiq, which I couldn’t find an eager mode) I found out that the eager mindset is wrong when it comes to unit testing.
By using eager mode I was treating my async tasks as sync and the views or methods that call those tasks need to run successfully without the async task.
So, in my opinion the best way to test this is to do something like (django with rest framework):