How not to make async task tests

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:


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):

url = reverse("user-list")
response =, data=sample_data)

# assert that nothing breaks and is working as expected

# call task as a normal function

# assert that the side effect of the task were applied

Dramatiq not having an eager mode was a blessing in disguise.