Unit Testing in Python — Patching, Mocks and Dependency Injection

How to test the difficult parts of your code

Martin Thoma
Level Up Coding
Published in
10 min readJul 9, 2020

--

Source: Andrea Piacquadio

Unit Testing in general is trivial with Python and pytest, but a lot of developers get frustrated when they have to patch dependencies away to make code testable. In this article, you will learn how to patch and use mocks. If you want to refresh basics about unit testing in…

--

--

I’m a Software Engineer with over 10 years of Python experience (Backend/ML/AI). Support me via https://martinthoma.medium.com/membership