hands-on lab

Python: Introduction to Patching

Difficulty: Intermediate
Duration: Up to 2 hours
Students: 97
Rating: 3.4/5
On average, students complete this lab in35m
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

Hands-on Lab UUID

Lab steps

0 of 10 steps completed.Use arrow keys to navigate between steps. Press Enter to go to a step if available.
  1. Web IDE Review
  2. Introduction
  3. Using: new
  4. Using: new_callable
  5. Using: spec and auto-spec
  6. Function Decorators
  7. Multiple Decorators
  8. Patching Test Cases
  9. Specific Patches
  10. Summary