Python: Introduction to Mocking

Lab Steps

lock
Web IDE Review
lock
Introduction to Mock
lock
Callables
lock
Call Assertions
lock
Inspecting Calls
lock
Magic Mock
lock
Side Effects
lock
Attributes
lock
Existing Objects
lock
Unittest
lock
Summary

The hands-on lab is part of this learning path

Ready for the real environment experience?

DifficultyIntermediate
Time Limit2h
Students26
Ratings
5/5
starstarstarstarstar

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

About the Author
Students94776
Labs26
Courses44
Learning paths57

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