我正在尝试测试 Celery 应用程序,这是我的代码
@celery.task(bind=True, default_retry_delay=30)
def convert_video(gif_url, webhook):
// doing something awesome
return
except Exception as exc:
raise convert_video.retry(exc=exc)
在我的测试中我有这个。
server.convert_video.apply(args=('some_gif', 'http://www.company.com?attachment_id=123')).get()
添加 bind=True, default_retry_delay=30
后,出现此错误
TypeError: convert_video() takes exactly 2 arguments (3 given)
最佳答案
说实话,我从来没有用过 celery ,但是快速浏览一下他们的docs对于 bind
参数来说:
The bind argument means that the function will be a “bound method” so that you can access attributes and methods on the task type instance.
通常,只有当这是类上的方法而不是独立函数时,您才会使用它。作为类上的方法,它的第一个参数是 self
。
关于python - 为什么向 Celery 添加参数会导致 Python 测试出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30744979/