Django testing in combination with celery

I am having trouble trying to evaluate how to test my application architecture. I already have 60% of my site complete, with full unit testing coverage (over all utility / lib functions, celery tasks as simple functions, etc.).

The problem comes when I try to test django views (simple functions) that do celery tasks (delay method).

Example:

def myview(request):
  ...
  mytask.delay(myval)
  ... 

      

What should be the correct way to test these scenes without creating a new task execution?

The obvious way is to create a condition before each call to delay the task, which is executed only if it is not in the test environment but seems really messy.

What advice?

+3


source to share


1 answer


Use the CELERY_ALWAYS_EAGER

settings for a test run.

This allows the function to be called immediately instead of being run as a task.




Example snippet of django settings:

if 'test' in sys.argv:
    CELERY_ALWAYS_EAGER = True

      

+3


source







All Articles