如何在django上测试时禁用芹菜任务

时间:2021-01-22 19:18:47

Im trying to test some functions that include a call for celery tasks. the tasks involves a call to 3rd party websites and i need to avoid it during tests.

我正在尝试测试一些功能,包括召唤芹菜任务。任务包括给第三方网站打电话,我需要在测试期间避免这样做。

Any idea how to disable all celery tasks during tests?

你知道怎么在测试中禁用所有芹菜吗?

1 个解决方案

#1


2  

Usually the "good method" imply doing Mocks. http://www.voidspace.org.uk/python/mock/

通常,“好方法”意味着做模拟。http://www.voidspace.org.uk/python/mock/

So you'll return example response from the site.

因此,您将返回站点的示例响应。

You can check on class declaration debug state and if True replace the class by the corresponding Mock

您可以检查类声明调试状态,如果为真,可以用相应的Mock替换类

#1


2  

Usually the "good method" imply doing Mocks. http://www.voidspace.org.uk/python/mock/

通常,“好方法”意味着做模拟。http://www.voidspace.org.uk/python/mock/

So you'll return example response from the site.

因此,您将返回站点的示例响应。

You can check on class declaration debug state and if True replace the class by the corresponding Mock

您可以检查类声明调试状态,如果为真,可以用相应的Mock替换类