$npx skillfedfor your agent

pytest-mock

Thin-wrapper around the mock package for easier use with pytest

Worth itPyPI TestingReleased Sep 2025105.0M downloads / moMITPure Python

Decision gist · record as of 2026-08-14

pure-Python wheel — pytest_mock-3.15.1-py3-none-any.whl
v3.15.1 · released 2025-09-16 · Python >=3.9 · 1 runtime deps: pytest

Yes. pytest-mock is a standard, actively maintained tool in the pytest ecosystem with no known vulnerabilities, permissive licensing, and minimal install friction. If you write pytest tests and need to mock objects, this plugin eliminates boilerplate and integrates cleanly with pytest's fixture system—it's a near-universal choice for pytest-based projects.AI-flagged interpretation of the facts on this page — verify before relying

Before you install

  • Requires pytest to be installed; Python 3.9 or later.
  • Low friction: pure Python wheel with only pytest as a runtime dependency.
  • Active maintenance with recent releases and 2037 repository stars; last commit on 2026-08-13 signals ongoing development.

License · maintenance · safety

MIT (permissive) — MIT license is permissive, allowing use in commercial and private projects with minimal restrictions—only attribution required.

last release 2025-09-16 (332 days) · last repo commit 2026-08-13 · 2,037 stars

0 known vulnerabilities (OSV.dev, 2026-08-14) · 105,035,819 downloads/mo, #329 on PyPI

Verify before relying

pip install pytest-mock

import os
from pytest_mock import MockerFixture

def test_example(mocker: MockerFixture):
    mocker.patch('os.remove')
    os.remove('file')
    os.remove.assert_called_once_with('file')
  • Whether the spy and stub utilities offer advantages over standard mock.patch usage patterns.
  • Performance characteristics when used in large test suites with many patches.
Same gist for agents: .md · .json

What it is and what it does

pytest-mock is a pytest plugin that wraps the mock library's patching API into a convenient fixture called `mocker`. Instead of manually managing patches and cleanup in your tests, you inject the mocker fixture and call methods like `mocker.patch()` to replace objects; pytest automatically undoes the patches after each test completes. The plugin also provides `spy` and `stub` utilities and uses pytest's introspection to give clearer output when comparing mock calls.

It's designed for developers writing pytest test suites who want to mock external dependencies—filesystem calls, network requests, database operations—without the boilerplate of manual setup and teardown. The single runtime dependency is pytest itself, making it a lightweight addition to any pytest workflow.

Use it for

  • Mock filesystem operations like os.remove in unit tests without affecting the actual filesystem.
  • Patch external API calls to test error handling and edge cases without hitting real endpoints.
  • Spy on method calls to verify that internal functions were invoked with expected arguments.
  • Stub out database operations during testing to isolate business logic from persistence layers.
  • Replace time.time or datetime.now in tests to verify time-dependent behavior deterministically.

Worth the install?

AI-flagged interpretation of the facts on this page. Verify before relying on it.

Worth it

Yes.

pytest-mock is a standard, actively maintained tool in the pytest ecosystem with no known vulnerabilities, permissive licensing, and minimal install friction. If you write pytest tests and need to mock objects, this plugin eliminates boilerplate and integrates cleanly with pytest's fixture system—it's a near-universal choice for pytest-based projects.

Install

pytest-mock on PyPI

Before you install

Low friction: pure Python wheel with only pytest as a runtime dependency. Active maintenance with recent releases and 2037 repository stars; last commit on 2026-08-13 signals ongoing development.

Requires pytest to be installed; Python 3.9 or later.

License in practice

MIT license is permissive, allowing use in commercial and private projects with minimal restrictions—only attribution required.

Quickstart

pip install pytest-mock

import os
from pytest_mock import MockerFixture

def test_example(mocker: MockerFixture):
    mocker.patch('os.remove')
    os.remove('file')
    os.remove.assert_called_once_with('file')

Verify before relying

  • Whether the spy and stub utilities offer advantages over standard mock.patch usage patterns.
  • Performance characteristics when used in large test suites with many patches.

Package facts

LicenseMIT permissive
Python supportSupports the current Python release >=3.9
Install frictionLow. Pure-Python wheel
Runtime dependencies
1 package
pytest
MaintenanceActively maintained 332 days since the last release
Last repo commit
First released
Downloads105,035,819 / month, #329 on PyPI 30-day window, as of 2026-08-14
Known vulnerabilitiesNone known OSV.dev, checked 2026-08-14
Classifiers
Development Status :: 5 - Production/StableFramework :: PytestIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Topic :: Software Development :: Testing

Evidence: pytest_mock-3.15.1-py3-none-any.whl

Tags

Capabilities
pytest mocking fixturemock patching in pytesttest doubles for pytestspy and stub utilitiesautomatic mock cleanuppytest mock integrationpatch objects in tests
Topics
testingmockingpytest-plugin
PyPI keywords
pytestmock

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 › “pytest mocking fixture”

  • pytest-mockProvides a pytest fixture that wraps the mock library's patching API,…
  • pytest-httpxpytest-httpx provides a pytest fixture that intercepts httpx requests…
  • pytest-localserverProvides pytest fixtures that spin up local HTTP and SMTP servers for…

Give your agent the search over MCP, or paste the wish link into any chat.

More Testing packages

pluggy Worth it
PyPI · Libraries · released May 2025

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.

MITpure Python · 3.9+aging
1.3Bdownloads / mo
pytest Worth it
PyPI · Libraries · released Jun 2026

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.

MITpure Python · 3.10+
1.1Bdownloads / mo
virtualenv Worth it
PyPI · Libraries · released Aug 2026

virtualenv creates isolated Python environments where packages can be installed independently without affecting the system Python or other projects.

MITpure Python · 3.9+
532.9Mdownloads / mo
coverage Worth it
PyPI · Testing · released Aug 2026

Coverage.py measures which lines of Python code are executed during test runs, reporting coverage percentages and identifying untested code paths.

Install it if you want to measure test completeness or enforce coverage thresholds in your project.

permissive licensepure Python · 3.10+
335.8Mdownloads / mo
pytest-asyncio Worth it
PyPI · Testing · released May 2026

pytest-asyncio is a pytest plugin that enables writing and running async test functions using the asyncio library, allowing developers to await code directly within test cases.

Install it if you write tests for any asyncio-based code.

Apache-2.0pure Python · 3.10+
275.9Mdownloads / mo
pytest-json-ctrf Worth it
PyPI · Testing · released Jul 2026

A pytest plugin that generates test reports in Common Test Report Format (CTRF) as JSON, compatible with pytest-xdist and pytest-playwright for distributed and browser-based testing.

Install it if you need CTRF-formatted test output for CI/CD integration or cross-tool reporting.

MITpure Python · 3.8+
273.0Mdownloads / mo

See also flexmock · kgb · pytest-stub · mockito · pytest-astropy · stubs · mock-open · testfixtures · pytest-sftpserver · wiremock