hands-on lab

Python: Introduction to Patching

Difficulty: Intermediate
Duration: Up to 2 hours
Students: 73
Rating: 3/5
Get guided in a real environmentPractice with a step-by-step scenario in a real, provisioned environment.
Learn and validateUse validations to check your solutions every step of the way.
See resultsTrack your knowledge and monitor your progress.

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

Updates

April 19th, 2023 - Updated theia to include autosave

Covered topics

Lab steps

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