unittest.mock

Stdlib — TestingPython 2.0+Intermediate

Mock objects for tests (Mock, MagicMock, patch)

Quick Info

Documentation
Official Docs
Python Version
2.0+
Dependencies
None — Python Standard Library
Install
Included with Python

Learn by Difficulty

Quick Example

python
import unittest.mock

print(f"Module: unittest.mock")
print(f"Contents: {dir(unittest.mock)[:10]}")

The unittest.mock module is part of Python's standard library. Mock objects for tests (Mock, MagicMock, patch).

Try in Playground

Tags

stdlibtestingdebugging