我试图使用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"}
结果
好吧,我想出来了,你需要把初始化放在模拟中,这样:
相关问题 更多 >
编程相关推荐