我尝试使用mock模拟HTTP请求调用,因为我不想这样做Behave
实际上叫它。所以我在下面的代码场景中
文件:matches.py
import request
def get_match():
response = request.get("https://example.com")
return response在我的步骤定义中match_steps.py对于behave,我有这样的想法:
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"} 结果
发布于 2020-01-20 10:17:30
好的,我想出来了,你需要把你的初始化放在mock里面,这样:
from mock import patch
from matches import get_match
with patch ('match') as mock_match:
mock_match.retun_value = {"status": "success"}
get_match()https://stackoverflow.com/questions/59784613
复制相似问题