Using the Python mock library to fake regular functions during tests
While writing unit tests in Python, there will often be times where you’ll need to fake the result of a function as testing against the actual function may be impossible. A simple example is a random function since one can’t predict what it will return. Another could be a database call for a database that’s only available in certain environments.
Python’s mock library is the de facto standard when mocking functions in Python, yet I have always struggled to understand it from the official documentation.
[Read More]