for example you need to mock nested function calls (chained functions) from Google DRIVE API
result = get_drive_service().files().insert(body='body', convert=True).execute()
so you need to patch through functions: service_mock(), files(), insert(), till last execute() response:
from mock import patch
with patch('path.to.import.get_drive_service') as service_mock:
service_mock.return_value.files.return_value.insert.
return_value.execute.return_value = {'key': 'value', 'status': 200}
Main scheme:
first.return_value.second.return_value.third.return_value.last.return_value = rsp
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…