Monitor performance issues & errors in your code

Testing without dependencies, mocking in Python

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

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:
Episode transcripts:

--- Stay in touch with us ---
Subscribe to us on YouTube:
Follow Talk Python on Mastodon: talkpython
Follow Michael on Mastodon: mkennedy

Want to go deeper? Check out our courses

Talk Python's Mastodon Michael Kennedy's Mastodon