嘲弄

2024-04-26 23:49:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用mock模拟HTTP请求调用,因为我不想实际调用它

所以我在matches.py文件中有这个代码场景:

import request

def get_match():
   response = request.get("https://example.com")
   return response

在我对behave的步骤定义match_steps.py中,我有以下内容:

def logoport_matches_response(context):
   mock_response = context.text # this is the payload will come from feature file
   with patch ('match') as mock_match:
      mock_match.get_match.return_value = {"status": "success"}

但这似乎不起作用,因为它仍在请求一个实际的HTTP请求

我需要模拟get_match方法来返回{"status": "success"}结果


Tags: 文件代码pyhttpgetreturnresponserequest