--- id: pytest-mock version: "3.15.1" license: MIT license_treatment: permissive maintenance: active --- # pytest-mock — Thin-wrapper around the mock package for easier use with pytest License: permissive · Maintenance: active · Popularity: top 1,000 on PyPI ## Install pip install pytest-mock uv add pytest-mock poetry add pytest-mock ## Description =========== pytest-mock =========== This plugin provides a ``mocker`` fixture which is a thin-wrapper around the patching API provided by the `mock package `_: .. code-block:: python import os class UnixFS: @staticmethod def rm(filename): os.remove(filename) def test_unix_fs(mocker): mocker.patch('os.remove') UnixFS.rm('file') os.remove.assert_called_once_with('file') Besides undoing the mocking automatically after the end of the test, it also provides other nice utilities such as ``spy`` and ``stub``, and uses pytest introspection when comparing calls. |python| |version| |anaconda| |docs| |ci| |coverage| |black| |pre-commit| .. |version| image:: http://img.shields.io/pypi/v/pytest-mock.svg :target: https://pypi.python.org/pypi/pytest-mock .. |anaconda| image:: https://img.shields.io/conda/vn/conda-forge/pytest-mock.svg :target: https://anaconda.org/conda-forge/pytest-mock .. |ci| image:: https://github.com/pytest-dev/pytest-mock/workflows/test/badge.svg :target: https://github.com/pytest-dev/pytest-mock/actions .. |coverage| image::... ## AI interpretation — verify before relying pytest-mock provides a `mocker` fixture that wraps the mock package's patching API for pytest, automatically cleaning up patches after each test and offering utilities like spy and stub. Verdict: pytest-mock is a stable, widely-used testing utility (top 1000 PyPI, 2037 stars, active maintenance) with no known vulnerabilities, low install friction, and permissive licensing. It is a safe, standard choice for mock-based testing in pytest projects. [View on SkillFed](https://skillfed.io/packages/pytest-mock) · [View on PyPI](https://pypi.org/project/pytest-mock/)