The Real Python Podcast

Overcoming Testing Obstacles With Python's Mock Object Library


Listen Later

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.

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.

Course Spotlight: Improving Your Tests With the Python Mock Object Library

Master Python testing with unittest.mock. Create mock objects to tame complex logic and unpredictable dependencies.

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:

    • Python 3.14.3 and 3.13.12 Released
    • Python 3.15.0 Alpha 6 Released
    • Django Security Releases Issued: 6.0.2, 5.2.11, and 4.2.28
    • Show Links:

      • Open Source AI We Use to Work on Wagtail – One of the core maintainers at Wagtail CMS shares what open source models have been working best for the project so far.
      • Dispatch From the Inaugural PyPI Support Specialist – Maria Ashna (Thespi-Brain on GitHub) is the inaugural PyPI Support Specialist and she’s written up how the first year went.
      • MicroPythonOS Graphical Operating System – MicroPythonOS lightweight OS for microcontrollers targets applications with graphical user interfaces with a look similar to Android/iOS.
      • Improving Your Tests With the Python Mock Object Library – Master Python testing with unittest.mock. Create mock objects to tame complex logic and unpredictable dependencies.
      • Need Switch-Case in Python? It’s Not Match-Case! – Python’s match-case is not a switch-case statement. If you need switch-case, you can often use a dictionary instead.
      • How to Think About Time in Programming – 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.
      • Projects:

        • Prezo: A TUI-based Presentation Tool for the Terminal
        • django-deadcode: Tracks URLs, Templates, and Django Views
        • Additional Links:

          • AI in the CMS: steering the ecosystem - Wagtail CMS
          • Episode #258: Supporting the Python Package Index
          • MicroPythonOS: A complete operating system for microcontrollers like the ESP32, inspired by Android and iOS.
          • MicroPythonOS - The Ultimate MicroPython Operating System
          • LVGL — Light and Versatile Embedded Graphics Library
          • Structural Pattern Matching in Python – Real Python
          • Textual
          • Level up your Python skills with our expert-led courses:

            • Improving Your Tests With the Python Mock Object Library
            • Testing Your Code With pytest
            • Using Python's assert to Debug and Test Your Code
            • Support the podcast & join our community of Pythonistas

              ...more
              View all episodesView all episodes
              Download on the App Store

              The Real Python PodcastBy Real Python

              • 4.7
              • 4.7
              • 4.7
              • 4.7
              • 4.7

              4.7

              139 ratings


              More shows like The Real Python Podcast

              View all
              The Changelog: Software Development, Open Source by Changelog Media

              The Changelog: Software Development, Open Source

              288 Listeners

              Software Engineering Daily by Software Engineering Daily

              Software Engineering Daily

              629 Listeners

              Talk Python To Me by Michael Kennedy

              Talk Python To Me

              583 Listeners

              Soft Skills Engineering by Jamison Dance and Dave Smith

              Soft Skills Engineering

              291 Listeners

              Super Data Science: ML & AI Podcast with Jon Krohn by Jon Krohn

              Super Data Science: ML & AI Podcast with Jon Krohn

              304 Listeners

              Python Bytes by Michael Kennedy and Brian Okken

              Python Bytes

              213 Listeners

              Syntax - Tasty Web Development Treats by Wes Bos & Scott Tolinski - Full Stack JavaScript Web Developers

              Syntax - Tasty Web Development Treats

              990 Listeners

              Darknet Diaries by Jack Rhysider

              Darknet Diaries

              8,090 Listeners

              Tech Brew Ride Home by Morning Brew

              Tech Brew Ride Home

              971 Listeners

              Practical AI by Practical AI LLC

              Practical AI

              215 Listeners

              AWS Podcast by Amazon Web Services

              AWS Podcast

              208 Listeners

              Django Chat by William Vincent and Carlton Gibson

              Django Chat

              75 Listeners

              Last Week in AI by Skynet Today

              Last Week in AI

              312 Listeners

              Machine Learning Street Talk (MLST) by Machine Learning Street Talk (MLST)

              Machine Learning Street Talk (MLST)

              99 Listeners

              The Pragmatic Engineer by Gergely Orosz

              The Pragmatic Engineer

              74 Listeners