How to Perform Mocking and Patching for Unit Tests in Python

Learn different ways to patch your functions in Unit tests with pytest

Lynn G. Kwong
Python in Plain English
4 min readApr 21, 2024

--

Image by Mohamed_hassan on Pixabay

In a previous post, we introduced the basic usage of pytest for writing various tests in Python. However, we didn’t delve into mocking and patching in unit tests, which allows you to replace parts of your system under test with mock objects and…

--

--

I’m a Software Developer (https://medium.com/@lynn-kwong) keen on sharing thoughts, tutorials, and solutions for the best practice of software development.