kev*_*kev 7 python testing django celery celery-task
我有几个芹菜任务,包含在我的Django测试中.不幸的是,当通过.delay()调用任务时,不会抛出异常.我将CELERY_ALWAYS_EAGER设置为True.
tasks.py
import celeryapp as app
@app.task()
def exception_task():
print 'CELERY_ALWAYS_EAGER:', app.conf['CELERY_ALWAYS_EAGER']
raise Exception('foo')
Run Code Online (Sandbox Code Playgroud)
tests.py
def test_exception_in_task(self):
from tasks import exception_task
exception_task.delay()
Run Code Online (Sandbox Code Playgroud)
产量
CELERY_ALWAYS_EAGER: True
.
----------------------------------------------------------------------
Ran 1 test in 0.686s
Run Code Online (Sandbox Code Playgroud)
删除.delay时,测试将退出并出现错误:
ERROR: test_exception_in_task
Exception: foo
Run Code Online (Sandbox Code Playgroud)
版本
celery==3.1.4
Django==1.6.4
Run Code Online (Sandbox Code Playgroud)