You’ve learned so much about mocking objects using unittest.mock!
Now, you’re able to:
- Use
Mockto imitate objects in your tests - Check usage data to understand how you use your objects
- Customize your mock objects’ return values and side effects
patch()objects throughout your codebase- See and avoid problems with using Python mock objects
You have built a foundation of understanding that will help you build better tests. You can use mocks to gain insights into your code that you would not have been able to get otherwise.
Here’s one last disclaimer: Beware of overusing mock objects! It’s easy to take advantage of the power of Python mock objects and mock so much that you actually decrease the value of your tests.

Chris James on May 17, 2020
I learned about
autospecI’m going to use that in my code, it will be a big time saver.mock.side_effecttakes as list ofreturn_valuesand exceptions, you can only do one callableside_effectat a time.Unix has a utility called
caland New Year’s Day 3030 is a Friday!