我正在使用side_effect进行动态模拟。
这是代码。// main functionn
from api import get_users_from_api
def get_users(user_ids):
for user_id in user_ids:
res = get_users_from_api(user_id)
// test script
def get_dynamic_users_mock(user_id):
mock_by_user_id = {
1: {
"id": 1,
"first_name": "John",
"last_name": "Doe",
...
},
2: {
"id": 2,
"first_name": "Jane",
"last_name": "Smith",
...
},
...
}
return mock_by_user_id[user_id]
@patch("api.get_users_from_api")
def test_get_users(self, mock_get_users)
user_ids = [1, 2, 3]
mock_get_users.side_effect = get_dynamic_users_mock # mock get_users_from_api
get_users(user_ids) # call main function
我想从
test_get_users
将额外参数发送到此
get_dynamic_users_mock
函数。
如何做?