Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 模仿芹菜任务呼叫_Python_Django_Celery_Pytest - Fatal编程技术网

Python 模仿芹菜任务呼叫

Python 模仿芹菜任务呼叫,python,django,celery,pytest,Python,Django,Celery,Pytest,我有一个芹菜任务需要嘲笑。它被称为:- def trigger_task(id): task_name(id).delay() 我尝试过使用它,但是因为我传递了一个参数,所以它没有得到正确的模拟 @patch('domain.tasks.tasks.task_name.delay') def test_abc: pass 如何模拟它?传递参数的方式是错误的-您需要将任何参数传递给任务,而不是delay(),即task\u name.delay(id)。然后你的模拟会像预期的那

我有一个芹菜任务需要嘲笑。它被称为:-

def trigger_task(id):
    task_name(id).delay()
我尝试过使用它,但是因为我传递了一个参数,所以它没有得到正确的模拟

@patch('domain.tasks.tasks.task_name.delay')
def test_abc:
    pass

如何模拟它?

传递参数的方式是错误的-您需要将任何参数传递给任务,而不是
delay()
,即
task\u name.delay(id)
。然后你的模拟会像预期的那样工作。是的,这就是问题所在。感谢您传递参数的方式是错误的-您需要将任务的任何参数传递给
delay()
,即
task\u name.delay(id)
。然后你的模拟会像预期的那样工作。是的,这就是问题所在。谢谢