This question is based on How to check client API using Python?
class MyClient(...): def _do_get(self, suffix): return requests.get(self.service_url + "/" + suffix).json() def do_stuff(self): return self._do_get("stuff")
This is a client example, and the response provider said that it mocks the method that makes the requests:
class MyClientWithMocks(MyClient): def _do_get(self, suffix): self.request_log.append(suffix) return self.send_result
and use it as follows:
def test_stuff(self): client = MyClientWithMocks(send_result="bar") assert_equal(client.do_stuff(), "bar") assert_contains(client.request_log, "stuff")
Aren't you mocking a function that receives a request (which is requests.get ) and not mocking _do_get ? Also, is it better to have a function that creates a do_stuff path to call _do_get and has _do_get returns the necessary output for easier testing?
source share