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

Overcoming Testing Obstacles With Python's Mock Object Library

The Real Python Podcast · Real Python

February 27, 202639m 41s

Audio is streamed directly from the publisher (dts.podtrac.com) as published in their RSS feed. Play Podcasts does not host this file. Rights-holders can request removal through the copyright & takedown page.

Show Notes

<p>Do you have complex logic and unpredictable dependencies that make it hard to write reliable tests? How can you use Python&rsquo;s mock object library to improve your tests? Christopher Trudeau is back on the show this week with another batch of PyCoder&rsquo;s Weekly articles and projects.</p> <p>Christopher shares details about his recent Real Python video course, &ldquo;Improving Your Tests With the Python Mock Object Library.&rdquo; He describes how mocking in Python with <code>unittest.mock</code> allows you to simulate complex logic or unpredictable dependencies, such as responses from external services. He covers how the <code>Mock</code> class can imitate real objects, and the <code>patch()</code> function lets you temporarily substitute mocks for real objects in your tests. </p> <p>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.</p> <p>This episode is sponsored by AgentField.</p> <div class="alert alert-primary" role="alert"> <p><strong>Course Spotlight:</strong> <a href="https://realpython.com/courses/improve-tests-mock-object-library/">Improving Your Tests With the Python Mock Object Library</a></p> <p>Master Python testing with unittest.mock. Create mock objects to tame complex logic and unpredictable dependencies.</p> </div> <p>Topics:</p> <ul> <li>00:00:00 &ndash; Introduction</li> <li>00:02:53 &ndash; Python 3.14.3 and 3.13.12 Released</li> <li>00:03:15 &ndash; Django Security Releases Issued: 6.0.2, 5.2.11, and 4.2.28</li> <li>00:03:36 &ndash; Open Source AI We Use to Work on Wagtail</li> <li>00:07:27 &ndash; Dispatch From the Inaugural PyPI Support Specialist</li> <li>00:09:01 &ndash; MicroPythonOS Graphical Operating System</li> <li>00:11:27 &ndash; Sponsor: AgentField</li> <li>00:12:21 &ndash; Improving Your Tests With the Python Mock Object Library</li> <li>00:17:30 &ndash; Need Switch-Case in Python? It&rsquo;s Not Match-Case!</li> <li>00:26:03 &ndash; Video Course Spotlight</li> <li>00:27:38 &ndash; How to Think About Time in Programming</li> <li>00:31:58 &ndash; Prezo: A TUI-based Presentation Tool for the Terminal</li> <li>00:34:52 &ndash; django-deadcode: Tracks URLs, Templates, and Django Views</li> <li>00:38:09 &ndash; Thanks and goodbye</li> </ul> <p>News:</p> <ul> <li><a href="https://pythoninsider.blogspot.com/2026/02/python-3143-and-31312-are-now-available.html">Python 3.14.3 and 3.13.12 Released</a></li> <li><a href="https://pythoninsider.blogspot.com/2026/02/python-3150-alpha-6.html">Python 3.15.0 Alpha 6 Released</a></li> <li><a href="https://www.djangoproject.com/weblog/2026/feb/03/security-releases/">Django Security Releases Issued: 6.0.2, 5.2.11, and 4.2.28</a></li> </ul> <p>Show Links:</p> <ul> <li><a href="https://wagtail.org/blog/open-source-ai-we-use-to-work-on-wagtail/">Open Source AI We Use to Work on Wagtail</a> &ndash; One of the core maintainers at Wagtail CMS shares what open source models have been working best for the project so far.</li> <li><a href="https://blog.pypi.org/posts/2026-01-26-a-year-and-a-half-as-inaugural-pypi-support-specialist/">Dispatch From the Inaugural PyPI Support Specialist</a> &ndash; Maria Ashna (Thespi-Brain on GitHub) is the inaugural PyPI Support Specialist and she&rsquo;s written up how the first year went.</li> <li><a href="https://www.cnx-software.com/2026/01/29/micropythonos-graphical-operating-system-delivers-android-like-user-experience-on-microcontrollers/">MicroPythonOS Graphical Operating System</a> &ndash; MicroPythonOS lightweight OS for microcontrollers targets applications with graphical user interfaces with a look similar to Android/iOS.</li> <li><a href="https://realpython.com/courses/improve-tests-mock-object-library/">Improving Your Tests With the Python Mock Object Library</a> &ndash; Master Python testing with unittest.mock. Create mock objects to tame complex logic and unpredictable dependencies.</li> <li><a href="https://www.pythonmorsels.com/switch-case-in-python/">Need Switch-Case in Python? It&rsquo;s Not Match-Case!</a> &ndash; Python&rsquo;s match-case is not a switch-case statement. If you need switch-case, you can often use a dictionary instead.</li> <li><a href="https://shanrauf.com/archive/how-to-think-about-time-in-programming">How to Think About Time in Programming</a> &ndash; Time is a complex thing to code. This article is a very deep dive, covering absolute measurement, civil time, modern time keeping, the mess that are timezones, and much more.</li> </ul> <p>Projects:</p> <ul> <li><a href="https://github.com/abilian/prezo">Prezo: A TUI-based Presentation Tool for the Terminal</a></li> <li><a href="https://github.com/nanorepublica/django-deadcode">django-deadcode: Tracks URLs, Templates, and Django Views</a></li> </ul> <p>Additional Links:</p> <ul> <li><a href="https://wagtail.org/blog/ai-in-the-cms-steering-the-ecosystem/">AI in the CMS: steering the ecosystem - Wagtail CMS</a></li> <li><a href="https://realpython.com/podcasts/rpp/258/">Episode #258: Supporting the Python Package Index</a></li> <li><a href="https://github.com/MicroPythonOS/MicroPythonOS">MicroPythonOS: A complete operating system for microcontrollers like the ESP32, inspired by Android and iOS.</a></li> <li><a href="https://micropythonos.com/">MicroPythonOS - The Ultimate MicroPython Operating System</a></li> <li><a href="https://lvgl.io/">LVGL — Light and Versatile Embedded Graphics Library</a></li> <li><a href="https://realpython.com/structural-pattern-matching/">Structural Pattern Matching in Python – Real Python</a></li> <li><a href="https://textual.textualize.io/">Textual</a></li> </ul> <p>Level up your Python skills with our expert-led courses:</p> <ul> <li><a href="https://realpython.com/courses/improve-tests-mock-object-library/">Improving Your Tests With the Python Mock Object Library</a></li> <li><a href="https://realpython.com/courses/testing-your-code-with-pytest/">Testing Your Code With pytest</a></li> <li><a href="https://realpython.com/courses/python-assert-statement/">Using Python&#x27;s assert to Debug and Test Your Code</a></li> </ul> <p><a rel="payment" href="https://realpython.com/join">Support the podcast &amp; join our community of Pythonistas</a></p>