hands-on lab
Python: Introduction to Mocking
Difficulty: Intermediate
Duration: Up to 2 hours
Students: 111
Rating: 3.6/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. 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
- Familiarity with the Python runtime
- Familiarity with the Python language syntax
- Familiarity with callables
- Familiarity with classes
- Familiarity with the built-in unittest module
Updates
April 19th, 2023 - Updated theia to enable autosave
Covered topics
Lab steps
Web IDE Review
Introduction to Mock
Callables
Call Assertions
Inspecting Calls
Magic Mock
Side Effects
Attributes
Existing Objects
Unittest
Summary