Thin-wrapper around the mock package for easier use with pytest
2k
Stars
157
Forks
12
Open issues
30
Contributors
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.
Inferred from signals mentioned in the README (tests, CI, type safety) — not a review of the actual code.
AI's overall editorial judgment — not an average of the bars above, can weigh other factors too.
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.
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 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.
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.
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.
Not documented in README excerpt. Coverage badge present (coveralls.io) suggests CI coverage tracking is active, but numeric threshold not stated.
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.
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
- 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.
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.
Newsletter
Get analyses like this every Monday
Free weekly digest of the most interesting open-source discoveries.
Languages
Information
- Language
- Python
- License
- MIT
- Last updated
- 1w ago
- Created
- 146mo ago
- Analyzed with
- anthropic/claude-haiku-4-5
Stars over time
Contributors over time
Top 100 contributors only — repos with more will plateau at 100.
Open issues
Spy with async function not registering calls until coroutine is awaited
mocker.stub() is a coroutine function
async_stub doesn't need to be awaited
spy on frozen dataclass
Allow use of custom mock implementations
Open pull requests
Top contributors
Similar repos
pytest-dev/pytest
pytest is a mature, widely-adopted testing framework for Python that simplifies...
pytest-dev/pluggy
pluggy is a minimal plugin system framework used as the core infrastructure for...
| Repository | Stars | Week Δ | Language | Score | Updated |
|---|---|---|---|---|---|
|
|
2k | — | Python | 8/10 | 1w ago |
|
|
14.3k | — | Python | 9/10 | 3d ago |
|
|
1.7k | — | Python | 9/10 | 4d ago |
|
|
8.6k | — | Python | 8/10 | 2d ago |
|
|
1.9k | — | Python | 8/10 | 2w ago |
|
|
1.4k | — | Python | 8/10 | 3w ago |
pytest-mock wraps stdlib mock; solves friction points (teardown, verbosity) but remains dependent on stdlib semantics. Not a replacement, an ergonomic layer.
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.mock is the underlying dependency; pytest-mock is agnostic to test runner but optimized for pytest. Unlikely to compete with unittest directly.
Serve narrower domains (HTTP mocking); pytest-mock is general-purpose patching. Not direct competitors.