hands-on lab

Python: Introduction to Mocking

Difficulty: Intermediate
Duration: Up to 2 hours
Students: 151
Rating: 3.6/5
On average, students complete this lab in40m
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. Replacing objects with fake implementations allows code to be tested independently of its dependencies. Allowing tests to be fast, predictable, and more reliable.

Expand your Python skills by learning to use the built-in unittest.mock module.

Learning Objectives

Explore how to replace Python objects during testing.

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

  • Mock
  • MagicMock
  • call

Intended Audience

  • Python Developers

Prerequisites

Updates

April 19th, 2023 - Updated theia to enable autosave

Covered topics

Hands-on Lab UUID

Lab steps

0 of 11 steps completed.Use arrow keys to navigate between steps. Press Enter to go to a step if available.
  1. Web IDE Review
  2. Introduction to Mock
  3. Callables
  4. Call Assertions
  5. Inspecting Calls
  6. Magic Mock
  7. Side Effects
  8. Attributes
  9. Existing Objects
  10. Unittest
  11. Summary