3 ms·
Frankly, find_definition should be additionally modified to take a function that consumes a url and returns json data. This way it's easily unit-testable.
by lenkite 6y ago
Frankly, find_definition should be additionally modified to take a function that consumes a url and returns json data. This way it's easily unit-testable.
- danuker 6y agoThat would be dependency injection. It is a valid way to design around side-effects. Another (equivalent) way to test it is to mock out requests.get and response.json using a mocking library: instead of performing real requests, do what the test wants (return correct data, return unexpected date, or throw an exception).