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
Post a Comment