丢失的芹菜测试库。
graveolens的Python项目详细描述
缺少Celerypython库的测试库。graveolens可以提供的一些功能包括:
- 向芹菜任务调用提供结果,而不影响代理。
- 确保您确切知道调用了哪些任务。
- 轻松断言任务调用的参数。
- 在芹菜中使用send_task可以轻松处理结果。
芹菜的二项式名称是Apium graveolens。
返回结果
frommy_app.celeryimportappimportgraveolensdeftest_my_task():withgraveolens.activate()ascelery:celery.add('my_app.task',{'done':True,'status':'OK'})result=app.send_task('my_app.task','test',id=3)# The result is an EagerResult from Celery.assertresult.get()=={'done':True,'status':'OK'}# You can also check ALL the calls that Celery received.assertlen(celery.calls)==1assertcelery.calls[0].name=='http://twitter.com/api/1/foobar'assertcelery.calls[0].args==('test',)assertcelery.calls[0].kwargs=={'id':3}
断言芹菜调用
默认情况下,如果结果被添加并未使用,则会引发AssertionError 当上下文管理器退出时,例如:
importgraveolensdeftest_my_task():withgraveolens.activate()ascelery:celery.add('my_app.task')# Assertion will be raised here because 'my_app.task' is never called.
可以使用assert_all_tasks_called标志将其配置为 activate()。
另外,如果调用芹菜任务时没有设置结果,则 graveolens.NotMockedTask将被筹集。
frommy_app.celeryimportappimportgraveolensdeftest_my_task():withgraveolens.activate()ascelery:try:result=app.send_task('my_app.task','test',id=3)exceptgraveolens.NotMockedTask:# Exception will be raised since my_app.task has no result.pass