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
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: alpopkes.com
100 Days of Code episode: talkpython.fm/186
Anna-Lena on Github: github.com
PyCon talk from Lisa Road (2018) - “Demystifying the patch function”: youtube.com
PyCon talk from Edwin Jung (2019) - Mocking and Patching Pitfalls: youtube.com
Keynote talk “Finding Magic in Python” (about magical universe
project): youtube.com
Blog post about mocking in Python: alpopkes.com
Stackoverflow post on difference between stubs and mocks: stackoverflow.com
Freezegun project: github.com
KI Macht Schule (AI goes to school): ki-macht-schule.de
Code Combat: codecombat.com
PDB++: github.com
Episode transcripts: talkpython.fm
--- Stay in touch with us ---
Subscribe to us on YouTube: youtube.com
Follow Talk Python on Mastodon: talkpython
Follow Michael on Mastodon: mkennedy
100 Days of Code episode: talkpython.fm/186
Anna-Lena on Github: github.com
PyCon talk from Lisa Road (2018) - “Demystifying the patch function”: youtube.com
PyCon talk from Edwin Jung (2019) - Mocking and Patching Pitfalls: youtube.com
Keynote talk “Finding Magic in Python” (about magical universe
project): youtube.com
Blog post about mocking in Python: alpopkes.com
Stackoverflow post on difference between stubs and mocks: stackoverflow.com
Freezegun project: github.com
KI Macht Schule (AI goes to school): ki-macht-schule.de
Code Combat: codecombat.com
PDB++: github.com
Episode transcripts: talkpython.fm
--- Stay in touch with us ---
Subscribe to us on YouTube: youtube.com
Follow Talk Python on Mastodon: talkpython
Follow Michael on Mastodon: mkennedy