mock
Rolling backport of unittest.mock for all Pythons
Decision gist · record as of 2026-08-14
Yes, if you need mocking in Python 3.6–3.9 or want a consistent backport across versions. No, if you're on Python 3.3+ and can use unittest.mock from the standard library directly—the backport adds no new features, only compatibility. The aging maintenance status (last release 529 days ago) is a minor concern but not a blocker, since the API is stable and there are no known vulnerabilities.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Low friction: pure Python wheel with no runtime dependencies.
- Maintenance is aging—last release was 529 days ago—but the repository remains active with recent commits and the package is stable (Production/Stable status).
License · maintenance · safety
permissive license (permissive) — Licensed under BSD (permissive), so you can use it freely in commercial and open-source projects without significant legal constraints.
last release 2025-03-03 (529 days) · last repo commit 2025-03-03 · 538 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 32,892,422 downloads/mo, #770 on PyPI
Alternatives
Verify before relying
pip install mock
from mock import Mock, patch
m = Mock()
m.method()
assert m.method.called- Whether the backport adds features or fixes beyond what unittest.mock in current Python versions provides
- Specific scenarios where installing this backport is preferable to using the standard library directly
What it is and what it does
mock is a rolling backport of Python's standard library unittest.mock module, packaged for use with Python 3.6 and later. Since unittest.mock became part of the standard library in Python 3.3, this package exists primarily to provide a consistent, up-to-date version of the mocking API across different Python versions. It lets you create mock objects to replace real components during testing, spy on how those mocks are called, and make assertions about their usage patterns.
The package has no runtime dependencies and installs as a pure Python wheel, making it lightweight and quick to add to any test suite. It's widely used (top 1000 on PyPI with millions of monthly downloads) and carries no known security vulnerabilities. However, maintenance is aging—the last release was over a year ago—so it may lag behind the latest standard library improvements if you're running a recent Python version where unittest.mock is already available.
Use it for
- Replace external API calls in unit tests to avoid network requests and ensure test isolation
- Verify that specific methods were called with expected arguments during test execution
- Stub out database connections or file I/O to speed up test runs and eliminate side effects
- Test error handling by configuring mocks to raise exceptions on demand
- Ensure consistent mock behavior across teams using different Python 3.6+ versions
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you need mocking in Python 3.6–3.9 or want a consistent backport across versions.
No, if you're on Python 3.3+ and can use unittest.mock from the standard library directly—the backport adds no new features, only compatibility. The aging maintenance status (last release 529 days ago) is a minor concern but not a blocker, since the API is stable and there are no known vulnerabilities.
Install
mock on PyPI
Before you install
Low friction: pure Python wheel with no runtime dependencies. Maintenance is aging—last release was 529 days ago—but the repository remains active with recent commits and the package is stable (Production/Stable status).
License in practice
Licensed under BSD (permissive), so you can use it freely in commercial and open-source projects without significant legal constraints.
Quickstart
pip install mock
from mock import Mock, patch
m = Mock()
m.method()
assert m.method.called
Verify before relying
- Whether the backport adds features or fixes beyond what unittest.mock in current Python versions provides
- Specific scenarios where installing this backport is preferable to using the standard library directly
Package facts
| License | permissive license permissive |
| Python support | Supports the current Python release >=3.6 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | None |
| Maintenance | Aging 529 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 32,892,422 / month, #770 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python ModulesTopic :: Software Development :: Testing |
Evidence: mock-5.2.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “unittest.mock backport”
- mockmock provides a backport of Python's standard library unittest.mock…
- calleeProvides argument matchers for unittest.mock that let you assert on…
- backports.tarfileProvides a backport of Python's tarfile module for use on Python…
Give your agent the search over MCP, or paste the wish link into any chat.
More Libraries packages
urllib3 is an HTTP client library that provides thread-safe connection pooling, SSL/TLS verification, multipart file uploads, request retries, compression support, and proxy handling for Python applications.
Requests is a Python HTTP library that simplifies sending HTTP/1.1 requests with automatic handling of headers, authentication, cookies, and response parsing.
Pluggy provides a plugin system that lets you define hook specifications and register implementations to be called in sequence, enabling extensible Python applications without tight coupling.
Install it if you're building an extensible application or framework.
Provides parsing, arithmetic, and recurrence rule computation for dates and times, with timezone support and iCalendar RFC compliance.
Install it if you need to parse flexible date strings, compute relative dates, handle timezones, or work with recurrence rules—it's the de facto choice for these tasks.
Six provides utility functions to write Python code that runs on both Python 2.7 and Python 3.3+, smoothing over language differences between the two versions.
pytest is a testing framework that lets you write test functions using plain assert statements and automatically discovers and runs them, with detailed failure reporting.
See also callee · types-mock · flake8-mock-spec · extras · flexmock · requests-mock · mock-open · pytest-mock · databricks-test · testpath