【发布时间】:2020-01-17 09:34:10
【问题描述】:
我正在尝试使用 mock 模拟 HTTP 请求调用,因为我不想 Behave 实际调用它。
所以我在matches.py 文件中有这个代码场景:
import request
def get_match():
response = request.get("https://example.com")
return response
在我的步骤定义中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"} 结果
【问题讨论】:
标签: python flask bdd python-mock python-behave