Reputation: 299
I'm having some trouble trying to figure how to test my app architecture. I've already 60% of my website complete, with full unit testing coverage (over all utility/lib functions, celery tasks as simple functions, and so on).
The problem arises when I try to test django views (plain functions) that executes celery tasks (delay method).
Example:
def myview(request):
...
mytask.delay(myval)
...
What should be the right way to test that scenes without really generating a new task execution?
The obvious way is to set up a condition before every task delay call, executing it only if it's not in test environment, but it seems really dirty.
Any tip?
Upvotes: 3
Views: 349
Reputation: 369054
Use CELERY_ALWAYS_EAGER
settings for test run.
It make the function to be called immediately instead of running it as a task.
Example django settings snippet:
if 'test' in sys.argv:
CELERY_ALWAYS_EAGER = True
Upvotes: 3