我试图断言包装在另一个函数中的修补 request.get() 调用的输入。
def get_data(*args):
# logic to define url, based on '*args'
url = 'some_url?arg1&arg3'
# call I want to patch and assert the url of
response = request.get(url)
# process response
stuff = 'processed_response'
return stuff
测试脚本:
def mock_response_200(url):
response = mock.MagicMock()
response.status_code = 200
response.json = mock.Mock(return_value={
0: {'key1': 'value1', 'key2': 'value2'}
})
return response
@mock.patch('request.get', new=mock_response_200)
def test_get_data():
arg1 = 'arg1'
arg2 = None
arg3 = 'arg3'
stuff = get_data(arg1, arg2, arg3)
# <assert input arguments of patched function here>
如何断言传递给 mocked_response_200 的 url?mocked_response_200 在 test_get_data 中不是“已知的”。
我已经在这里查看了其他帖子这一篇很接近,但答案使用了不同的补丁方法。任何帮助将不胜感激。
拉莫斯之舞
慕婉清6462132
慕标5832272
相关分类