stubs
Tools for setting up stubs and mocks.
What it is and what it does
stubs is a lightweight testing utility that lets you temporarily replace a function's behavior using a context manager and matcher expressions. You define conditions (like `_ >= 3`) and specify what the function should return when those conditions are met, then wrap your test code in a `with` block that automatically reverts the stub when done.
The package was designed for Python 3.4 and Python 3.5 and has not been maintained since its initial release in 2016-10-31. It has no external runtime dependencies, making installation trivial, but its age means you should verify compatibility with your current Python version before relying on it.
Use it for:
- Isolate a function's behavior in unit tests by returning fixed values when specific argument patterns match
- Test code paths that depend on a function's return value without modifying the function itself
- Verify that your code handles different function outputs correctly by stubbing responses for different input conditions
- Temporarily replace functions during test runs without setting up a full mocking framework
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides a context-manager syntax for temporarily replacing function behavior with stub implementations that match specified conditions, reverting after the block exits.
No. While the package is permissively licensed and has zero dependencies, it has been abandoned for over 3574 days with no updates since 2016-10-31. Unless you are maintaining legacy code that already uses stubs, you should choose a currently maintained alternative for new projects.
Install
stubs on PyPI
pip
pip install stubsuv
uv add stubspoetry
poetry add stubsInstalling stubs
Before you install
Installation is frictionless with no runtime dependencies. However, the package has been abandoned since its only release on 2016-10-31 and has not been updated in over 3574 days, raising concerns about compatibility with modern Python versions.
License in practice
Licensed under Apache 2.0 (permissive), so you can use, modify, and distribute the package freely in most contexts without restriction.
Quickstart
pip install stubs
from stubs import stub
def f(x):
return x * 2
with stub[f](_ >= 3) >> 5:
print(f(3)) # prints 5
Package targets Python 3.4 and 3.5; compatibility with modern Python versions is unverified.
Verify before relying
- Whether the package actually works with Python versions beyond 3.5 given its age and lack of updates
- Whether the matcher syntax and context-manager API remain compatible with current testing frameworks
- Real-world usage patterns and whether this approach is still considered idiomatic in modern Python testing
Package facts
| License | Apache 2.0 (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 3,574 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 92,504/month — #13,448 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: stubs-1.0.0-py3-none-any.whl
Keywords: development, testing, mocking
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
pretendPretend provides a lightweight library for…
permissive · top 15,000 on PyPI
pytest-stubA pytest plugin that replaces package, module,…
permissive · top 15,000 on PyPI
mockitoMockito is a spying and stubbing framework for…
permissive · top 5,000 on PyPI
flexmockflexmock creates mock, stub, spy, and fake…
permissive · top 15,000 on PyPI
pytest-mockProvides a pytest fixture that wraps the mock…
permissive · top 1,000 on PyPI
tempenvTemporarily override environment variables…
permissive · top 15,000 on PyPI
requests-mockIntercepts and mocks HTTP requests made through…
permissive · top 1,000 on PyPI
types-mockProvides type stubs for the mock library,…
permissive · top 5,000 on PyPI
django-mock-queriesMocks Django QuerySet operations in memory for…
permissive · top 15,000 on PyPI
flake8-mock-specA flake8 plugin that enforces the use of the…
permissive · top 15,000 on PyPI