The Real Python Podcast

Overcoming Testing Obstacles With Python's Mock Object Library

22 snips
Feb 27, 2026
Christopher Trudeau, Real Python contributor and course author, walks through using unittest.mock to simulate complex logic and unpredictable dependencies. He explains Mock and patch() in accessible terms. The conversation also touches on release news, MicroPythonOS, match-case vs ifs, time handling in code, and tools for Django and terminal presentations.
Ask episode
AI Snips
Chapters
Transcript
Episode notes
ANECDOTE

MicroPythonOS Brings Touchscreen OS To ESP32

  • MicroPythonOS brings an Android-like GUI to microcontrollers using LVGL and runs on ESP32 and desktop.
  • Christopher Trudeau highlights features: App Store, touch gestures, Wi-Fi manager, OTA updates and example apps like launcher and settings.
INSIGHT

Mocking Makes Tests Deterministic Not Empty

  • Mocking isn't about removing code from tests but controlling external behavior to make tests deterministic.
  • Christopher Trudeau uses date and randomness examples to show you fake external services for reliable test outcomes.
ADVICE

Use Mocking To Control External Dependencies

  • Use unittest.mock to control unpredictable dependencies in tests.
  • Christopher Trudeau shows patch to substitute imports like picknum.randint so tests get deterministic return values instead of real randomness.
Get the Snipd Podcast app to discover more snips from this episode
Get the app