我的Django测试中包含一些芹菜任务。不幸的是,通过.delay()调用任务时不会引发异常。我将CELERY_ALWAYS_EAGER设置为True。
task.py
import celeryapp as app
@app.task()
def exception_task():
print 'CELERY_ALWAYS_EAGER:', app.conf['CELERY_ALWAYS_EAGER']
raise Exception('foo')
tests.py
def test_exception_in_task(self):
from tasks import exception_task
exception_task.delay()
输出
CELERY_ALWAYS_EAGER: True
.
----------------------------------------------------------------------
Ran 1 test in 0.686s
删除.delay时,测试会退出,并出现预期的错误:
ERROR: test_exception_in_task
Exception: foo
版本号
celery==3.1.4
Django==1.6.4
看来我还必须将CELERY_EAGER_PROPAGATES_EXCEPTIONS设置为True。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句