3 - Mocking and Patching
Enroll to start learning
You’ve not yet enrolled in this course. Please enroll for free to listen to audio lessons, classroom podcasts and take practice test.
Practice Questions
Test your understanding with targeted questions
What is the purpose of mocking in software testing?
💡 Hint: Think about what external factors could affect a test.
What is the Mock object in Python?
💡 Hint: Recall the class from the unittest.mock module.
4 more questions available
Interactive Quizzes
Quick quizzes to reinforce your learning
What is mocking used for in testing?
💡 Hint: Think about what isolating tests helps achieve.
True or False: Patching is used to permanently change an object's behavior.
💡 Hint: Consider the duration of the object's changed state.
1 more question available
Challenge Problems
Push your limits with advanced challenges
Develop a mock for a database call within an application. Create a test that verifies database interaction using this mock.
💡 Hint: Think of how you can use .return_value to simulate responses.
Using patching, write a test that checks if your code correctly handles network errors when calling an API.
💡 Hint: Consider using mock_get.side_effect for simulating an exception.
Get performance evaluation
Reference links
Supplementary resources to enhance your learning experience.