Python Mocking — Tutorial

Kamal Hussain
5 min readMay 19, 2021

Writing unit tests for programs that have external dependencies is tricky. One approach is mocking external dependencies. For example, if your program is writing to a MySQL database, you may not want to actually write to the database when you run unit tests. Instead, you can use a mock to simulate this operation.

Python’s unittest.mock allows you to replace parts of your program with mock objects and test various…

--

--