python - How to test code that uses an object and its methods? -


i trying unit-test following code py.test:

def get_service_data():         client = requests.session()     # task on client object      resp = client.get('https://apiendpoint.xxx.com/yyy/', params={...})     temp_json = resp.json()      result = []     # lots of processing on temp_json     return result 

however, if monkeypatch requests.session(), mocked object not have get() method. if patch requests.session.get(), test code output error message:

>       monkeypatch.setattr('requests.session.get', lambda: {}) e       failed: object <function session @ 0x1046e3500> has no attribute 'get' 

how should test above code?


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -