Python Mocking & Patching with unittest.mock
A Python mock is a stand-in object you drop into a test so it never touches the real API (Application Programming Interface), database, or email server. This post walks through the patterns that make unittest.mock click: the @patch decorator, MagicMock, side_effect, return_value, and the one rule about WHERE to patch that trips up almost everyone. “A test that talks to a database is not a unit test.” Michael Feathers, Working Effectively with Legacy Code Last Updated: July 2026 | Tested ... Read More
