pytest-dev

pytest-dev/pytest-mock

Python MIT Dev Tools

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

2k stars
157 forks
recent
GitHub

2k

Stars

157

Forks

12

Open issues

30

Contributors

v3.15.1 16 Sep 2025

AI Analysis

pytest-mock is a thin wrapper around Python's mock library that provides a convenient `mocker` fixture for pytest, simplifying mock patching and automatically cleaning up after tests. It serves developers writing unit tests in Python who want cleaner, more pytest-native mocking syntax without manual cleanup. This is a specialized testing tool for Python developers, not a general-purpose library.

Dev Tools Testing Tool Discovery value: 3/10
Documentation 8/10
Activity 9/10
Community 8/10
Code quality 8/10

Inferred from signals mentioned in the README (tests, CI, type safety) — not a review of the actual code.

Overall score 8/10

AI's overall editorial judgment — not an average of the bars above, can weigh other factors too.

testing mocking pytest python fixtures
Actively maintained Well documented MIT licensed Niche/specialized use case Beginner friendly Production ready
Deep Analysis · Based on README and public signals
1w ago

Pytest plugin providing ergonomic mock fixture with automatic cleanup

pytest-mock is a thin wrapper around Python's standard mock library, exposing a pytest fixture that simplifies patching in tests. It handles automatic cleanup, provides spy/stub utilities, and integrates pytest's call introspection for better assertion messages. Widely adopted within the pytest ecosystem; appears to be standard tooling for pytest-based test suites that need mocking.

Origin

Created in 2014 as part of the pytest-dev organization. Emerged to reduce boilerplate when using mock.patch() directly in pytest tests—solving the common friction of manual teardown and verbose syntax. Has maintained steady, modest growth over 12 years.

Growth

Growth has been gradual and plateau-like rather than explosive. 2,030 stars over 12 years suggests steady adoption as a recommended pytest pattern rather than viral growth. Recent activity (commit 2026-06-30, 4 stars in last 7 days) indicates ongoing maintenance and slow, stable usage growth. Likely benefits from being part of pytest-dev ecosystem and word-of-mouth recommendation in testing communities.

In production

Adoption not formally verified in README, but circumstantial evidence is strong: (1) part of official pytest-dev org; (2) 2,030 stars with 157 forks suggests moderate, stable adoption; (3) professional support available via Tidelift; (4) PyPI and conda-forge distribution; (5) active CI and documentation maintenance. Likely used across many pytest-dependent projects, but explicit testimonials or usage numbers not present in README.

Code analysis
Architecture

Based on README, appears to be a thin wrapper providing a `mocker` fixture that delegates to the standard `mock` package. Likely handles fixture lifecycle (setup/teardown), spy/stub abstractions, and pytest introspection integration. Implementation details not visible from metadata; README suggests architectural simplicity is intentional.

Tests

Not documented in README excerpt. Coverage badge present (coveralls.io) suggests CI coverage tracking is active, but numeric threshold not stated.

Maintenance

Last push 2026-06-30 (same as evaluation date) indicates active maintenance. README shows comprehensive CI/CD setup (GitHub Actions, coverage tracking, pre-commit), professional documentation on ReadTheDocs, and Tidelift professional support offering. These signals suggest sustained, responsible stewardship rather than hobby project.

Honest verdict

ADOPT IF: you are writing pytest tests and need to mock functions/objects with pytest-friendly syntax, automatic cleanup, and better assertion messages. The thin-wrapper approach keeps learning curve low. AVOID IF: you are not using pytest (use stdlib mock directly) or if your mocking needs are extremely specialized (e.g., only HTTP mocking, where domain-specific tools may be better). MONITOR IF: you need to ensure the plugin stays compatible with major Python/pytest version changes; the project appears stable but has a small maintainer pool typical of pytest-dev plugins.

Independent dimensions

Mainstream potential

3/10

Technical importance

6/10

Adoption evidence

7/10

Risks
  • Dependency on pytest version compatibility; if pytest's fixture system or introspection changes, this plugin requires updates. No evidence of active risk monitoring in README.
  • Small maintainer pool (typical of pytest-dev) means bus factor risk. No succession planning visible in README.
  • Depends on stdlib mock package stability; deprecations or breaking changes in mock could require plugin updates.
  • README shows no explicit guarantee of Python version support window; unclear if project maintains support for older Python versions that tests may still run on.
  • Adoption not formally quantified; if usage has plateaued, maintenance may eventually become reactive rather than proactive.
Prediction

pytest-mock will likely remain a stable, slowly-growing fixture in the pytest ecosystem. Unlikely to see exponential adoption (it solves a solved problem elegantly rather than enabling new capabilities). Most likely trajectory: continued maintenance as a standard pytest recommendation, with adoption tied to overall pytest growth. May eventually merge into pytest core if pytest absorbs mock utilities.

0 found this helpful

Newsletter

Get analyses like this every Monday

Free weekly digest of the most interesting open-source discoveries.

Languages

Python
100%

Information

Language
Python
License
MIT
Last updated
1w ago
Created
146mo ago
Analyzed with
anthropic/claude-haiku-4-5

Stars over time

Loading…

Contributors over time

Top 100 contributors only — repos with more will plateau at 100.

Loading…

Similar repos

pytest-dev

pytest-dev/pytest

pytest is a mature, widely-adopted testing framework for Python that simplifies...

14.3k Python Dev Tools
pytest-dev

pytest-dev/pluggy

pluggy is a minimal plugin system framework used as the core infrastructure for...

1.7k Python Dev Tools
getmoto

getmoto/moto

Moto is a Python library that mocks AWS services for testing purposes, allowing...

8.6k Python Dev Tools
pytest-dev

pytest-dev/pytest-xdist

pytest-xdist is a pytest plugin that enables distributed test execution across...

1.9k Python Dev Tools
ionelmc

ionelmc/pytest-benchmark

pytest-benchmark is a pytest fixture that enables benchmarking of Python code...

1.4k Python
vs. alternatives
unittest.mock (standard library)

pytest-mock wraps stdlib mock; solves friction points (teardown, verbosity) but remains dependent on stdlib semantics. Not a replacement, an ergonomic layer.

pytest built-in monkeypatch fixture

pytest provides monkeypatch for similar use cases. pytest-mock differentiates via mock.patch() semantics, spy/stub utilities, and better assertion introspection. Different niche rather than direct competition.

unittest (standard library)

unittest.mock is the underlying dependency; pytest-mock is agnostic to test runner but optimized for pytest. Unlikely to compete with unittest directly.

responses / vcrpy (HTTP mocking)

Serve narrower domains (HTTP mocking); pytest-mock is general-purpose patching. Not direct competitors.