mocking

Mocking in python tests: practical examples

What is mocking when it comes to python tests? Mocking is a way to simulate and control the behavior of functions or objects. Typically this type of control is necessary when unit testing code that deals with systems external to our own code. Why mock external systems? The main issue is with external systems unpredictability, we have limited control over the state of these external systems, making tests potentially very brittle. For example when code reads data from disk or a database. If there is a piece of functionality that reads and modifies files on disk we would have to…