Mock objects and patching
First of all, in Python, these fake objects are called mocks. Up to Version 3.3, the mock library was a third-party library that basically every project would install via pip but, from Version 3.3, it has been included in the standard library under the unittest module, and rightfully so, given its importance and how widespread it is.
The act of replacing a real object or function (or in general, any piece of data structure) with a mock, is called patching. The mock library provides the patch tool, which can act as a function or class decorator, and even as a context manager that you can use to mock things out. Once you have replaced everything you don't need to run with suitable mocks, you can pass to the second ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access