Real Python Podcast E286 Title Image

Episode 286: Overcoming Testing Obstacles With Python's Mock Object Library

The Real Python Podcast

Feb 27, 2026 39m intermediate ai django stdlib testing

Do you have complex logic and unpredictable dependencies that make it hard to write reliable tests? How can you use Python’s mock object library to improve your tests? Christopher Trudeau is back on the show this week with another batch of PyCoder’s Weekly articles and projects.

Episode Sponsor:

Christopher shares details about his recent Real Python video course, “Improving Your Tests With the Python Mock Object Library.” He describes how mocking in Python with unittest.mock allows you to simulate complex logic or unpredictable dependencies, such as responses from external services. He covers how the Mock class can imitate real objects, and the patch() function lets you temporarily substitute mocks for real objects in your tests.

We also share other articles and projects from the Python community, including a collection of recent releases, using open source AI at Wagtail, updates from the inaugural PyPI Support Specialist, a lightweight OS for microcontrollers in MicroPythonOS, why match-case is not necessarily switch-case for Python, thinking about time in programming, a TUI-based presentation tool for the terminal, and a tool to check Django projects for dead code.

This episode is sponsored by AgentField.

Topics:

  • 00:00:00 – Introduction
  • 00:02:53 – Python 3.14.3 and 3.13.12 Released
  • 00:03:15 – Django Security Releases Issued: 6.0.2, 5.2.11, and 4.2.28
  • 00:03:36 – Open Source AI We Use to Work on Wagtail
  • 00:07:27 – Dispatch From the Inaugural PyPI Support Specialist
  • 00:09:01 – MicroPythonOS Graphical Operating System
  • 00:11:27 – Sponsor: AgentField
  • 00:12:21 – Improving Your Tests With the Python Mock Object Library
  • 00:17:30 – Need Switch-Case in Python? It’s Not Match-Case!
  • 00:26:03 – Video Course Spotlight
  • 00:27:38 – How to Think About Time in Programming
  • 00:31:58 – Prezo: A TUI-based Presentation Tool for the Terminal
  • 00:34:52 – django-deadcode: Tracks URLs, Templates, and Django Views
  • 00:38:09 – Thanks and goodbye

News:

Show Links:

Projects:

Additional Links: