如何在pytest中存根芹菜任务?

时间:2019-04-01 18:42:34

标签: python flask celery pytest

我无法完成芹菜任务。

这是任务本身:

@celery.task
def hello_task:
  print("hello")

这是我的服务正在调用任务:

class Hello:
    def __init__(self, context: ContextObject):
        self.context = context

    def call_task(self) -> None:
        hello_task.delay()

我在Hello类中编写了一个测试call_task的测试:

    @patch('path.to.hello_task')
    def test_create_attestations(self, task_mock):
        self.service.call_task()
        task_mock.assert_called()

我遇到的问题是@patch语句没有取消对hello_task的调用,因此它仍在打印hello。我想完全取消celery任务,只是断言它已被调用。

有什么建议吗?

0 个答案:

没有答案