python - 为什么向 Celery 添加参数会导致 Python 测试出错?

标签 python celery python-mock

我正在尝试测试 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/

相关文章:

python - Matplotlib:轮廓上的颜色条没有条纹

python - Celery 连接代理丢失导致 CPU 使用率达到 100%

Python测试: How do I mock outside of the testing scope?

python - 在单个模拟变量中跨不同文件模拟相同的 Python 函数

python - 如何找到字典和列表之间的匹配项以从匹配项创建新列表?

python - 获取副词和形容词对应的动词和名词

python - 删除 `settings.py` 中 celery scheduler 的周期性任务不会删除实际任务

python - celery 死于 DBPageNotFoundError

python - 在同一个python函数中模拟两个具有不同返回值的redis hget

python - 多个函数中的相同列表/字典