Get $100 free credit - Build your next big idea @

Testing without dependencies, mocking in Python

Episode #287, published Wed, Oct 21, 2020, recorded Mon, Aug 24, 2020.

This episode is carbon neutral.
We know our unit tests should be relatively independent from other parts of the system. For example, running a test shouldn't generally call a credit card possessing API and talk to a database when your goal is just to test the argument validation.

And yet, your method does all three of those and more. What do you do? Some languages use elaborate dependency passing frameworks that go under the banner of inversion of control (IoC) and dependency injections (DI). In Python, the most common fix is to temporarily redefine what those two functions do using patching and mocking.

On this episode, we welcome back Anna-Lena Pokes to talk us through the whole spectrum of test doubles, dummies, mocks, and more.

Links from the show

Anna-Lena's personal site:
100 Days of Code episode:
Anna-Lena on Github:
PyCon talk from Lisa Road (2018) - “Demystifying the patch function”:
PyCon talk from Edwin Jung (2019) - Mocking and Patching Pitfalls:
Keynote talk “Finding Magic in Python” (about magical universe
Blog post about mocking in Python:
Stackoverflow post on difference between stubs and mocks:
Freezegun project:
KI Macht Schule (AI goes to school):
Code Combat:

Want to go deeper? Check out our courses

Anna-Lena Popkes
Anna-Lena Popkes
Anna-Lena Popkes is an enthusiastic learner who is always looking for new projects and challenges. She is deeply fascinated by machine learning and its applications in questions that affect and benefit many people.
Episode sponsored by
Ads served ethically
Click to show comments

Individuals can support this podcast directly via Patreon. Corporate sponsorship opportunities available here.
Become a friend of the show
Stay in the know and get a chance to win our contests.
See our privacy statement about email communications.