Autospeccing and Patch
Explore how to apply autospeccing to generate mocks with authentic attributes and call signatures, and use the patch function to mock dependencies like web requests. This lesson helps you understand how to prevent side effects during testing by simulating objects and controlling their behavior.
We'll cover the following...
Auto-speccing
The mock module also supports the concept of auto-speccing. The autospec allows us to create mock objects that contain the same attributes and methods of the objects that we are replacing with our mock.
They will even have the same call signature as the real object!
You can create an autospec with the create_autospec function or by
passing in the autospec argument to the mock library’s patch
decorator.
Example of autospec
For now, let’s look at an easy-to-understand example of the autospec ...