Python: Introduction to Patching

Lab Steps

lock
Web IDE Review
lock
Introduction
lock
Using: new
lock
Using: new_callable
lock
Using: spec and auto-spec
lock
Function Decorators
lock
Multiple Decorators
lock
Patching Test Cases
lock
Specific Patches
lock
Summary

The hands-on lab is part of this learning path

Ready for the real environment experience?

DifficultyIntermediate
Time Limit2h
Students24
Ratings
3/5
starstarstarstar-borderstar-border

Description

The unittest.mock module is Python's built-in mocking and patching module. Used to replace objects with fake implementations during testing.

This lab introduces the unittest.mock.patch callable through hands-on learning.

Learning Objectives

Explore the fundamental building blocks of the unittest.mock module.

At the end of this lab you'll be familiar with:

  • The unittest.mock.patch callable
  • Using patch as a context manager
  • Using patch as a callable decorator

Intended Audience

  • Python Developers

Prerequisites

About the Author
Students96068
Labs28
Courses46
Learning paths54

Ben Lambert is a software engineer and was previously the lead author for DevOps and Microsoft Azure training content at Cloud Academy. His courses and learning paths covered Cloud Ecosystem technologies such as DC/OS, configuration management tools, and containers. As a software engineer, Ben’s experience includes building highly available web and mobile apps. When he’s not building software, he’s hiking, camping, or creating video games.

Covered Topics