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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -