【发布时间】:2021-01-23 16:55:57
【问题描述】:
我有一个方法,它调用两个不同的端点并验证那里的响应。
def foo_bar:
status_1 = requests.post(
"http://myapi/test/status1", {},
headers=headers)
status_2 = requests.post(
"http://myapi/test/status2", {},
headers=headers)
# and check the responses ...
我想像这样模拟 pytest 中的两个 url:
def foo_test:
with requests_mock.Mocker() as m1:
m1.post('http://myapi/test/status1',
json={},
headers={'x-api-key': my_api_key})
m1.post('http://myapi/test/status2',
json={},
headers={'x-api-key': my_api_key})
它总是抛出错误
**NO mock address: http://myapi/test/status2**
似乎是它唯一的模拟第一个网址。
那么有没有办法在一种方法中模拟多个 url?
【问题讨论】:
标签: python-3.x python-requests python-mock requests-mock