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

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

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.
X
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.