Understanding the Python Mock Object Library

Python’s unittest.mock library is a tool that helps you create mock objects to simulate complex logic and unpredictable dependencies.
This helps you write valuable tests that verify your application logic is correct, reliable, and efficient.

You’ll begin by learning about what mocking is and how you can use it to improve your tests.

What Is Mocking?

A mock object substitutes and imitates a real object within a testing environment. Using mock objects is a versatile and powerful way to improve the quality of your tests. This is because by using Python mock objects, you can control your code’s behavior during testing.

For example, if your code makes HTTP requests to external services, then your tests execute

 

 

 

To finish reading, please visit source site