我正在使用带有Django 1.6的Celery 3.1.11.我一直在寻找,但我最近没有找到很多关于芹菜的问题.(3.1)
我试图通过manage.py运行单元测试:
>> python manage.py test calculationApp
Run Code Online (Sandbox Code Playgroud)
在我的tests.py for calculationApp中创建任务:
c = calculateCarbon.delay(project.id)
r = AsyncResult(c.id).ready()
print "c.backend: %s" % (c.backend)
print "AsyncResult(c.id).ready(): %s" % (r)
print "AsyncResult(c.id).state: %s" % (AsyncResult(c.id).state)
print "AsyncResult(c.id).result: %s" % (AsyncResult(c.id).result)
while not r:
r = AsyncResult(c.id).ready()
Run Code Online (Sandbox Code Playgroud)
当我运行单元测试时,测试卡在测试中并且从未准备好(它永远不会超过while循环),我将其作为输出:
/usr/lib/python2.7/dist-packages/numpy/core/_methods.py:96: RuntimeWarning: invalid value encountered in double_scalars
ret = ret / float(rcount)
c.backend: None
AsyncResult(c.id).ready(): False
AsyncResult(c.id).state: PENDING
AsyncResult(c.id).result: None
Run Code Online (Sandbox Code Playgroud)
此时我必须按CTRL + C两次.
我正在阅读Celery 3.0 Docs - Unit Testing,它告诉我要设置.
CELERY_ALWAYS_EAGER = True
TEST_RUNNER …Run Code Online (Sandbox Code Playgroud)