pretend
A library for stubbing in Python
What it is and what it does
Pretend is a test-focused library that makes it easy to create stub objects—objects that return fixed values rather than performing computation. Unlike mocking libraries, stubs are simpler and more focused: you define what attributes or methods return, and the stub returns exactly that. The library includes a stub() function to create objects with predefined attributes and methods, a raiser() helper to make stubs raise exceptions, and a call_recorder() utility to track how a stub was invoked.
The design philosophy emphasizes passing stubs as arguments to code under test rather than monkey-patching them globally. This encourages tests that verify computation results rather than implementation details. Pretend has no runtime dependencies and installs cleanly via pip, making it a minimal addition to a test suite.
Use it for:
- Create test doubles with fixed return values to isolate code under test from external dependencies
- Stub methods that should raise exceptions to test error-handling paths without triggering real failures
- Record function calls during tests to verify a stub was invoked with expected arguments
- Replace real objects in unit tests with lightweight stubs that return pre-canned responses
- Test code that depends on external APIs by providing stub objects with fixed attributes
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Pretend provides a lightweight library for creating stub objects in tests that return pre-canned responses without computation, plus utilities for recording calls and raising exceptions.
Yes, if you prefer lightweight stubs over full mocking frameworks and your test suite targets Python versions the package supports. The library is dormant but stable, carries no known vulnerabilities, and has zero dependencies. However, verify compatibility with your Python version—classifiers only list up to 3.6, and the last release was 2018-04-14. If you need active maintenance or support for modern Python versions, consider alternatives.
Install
pretend on PyPI
pip
pip install pretenduv
uv add pretendpoetry
poetry add pretendInstalling pretend
Before you install
Installation is straightforward with no runtime dependencies. The package is dormant (last release 2018-04-14, last commit 2024-06-22) but remains in production/stable status with no known vulnerabilities.
License in practice
BSD license (permissive) allows use in most projects with minimal restrictions; attribution is typically required but commercial and private use are permitted.
Quickstart
pip install pretend
from pretend import stub, raiser, call_recorder
x = stub(country_code="US")
f = call_recorder(lambda a: a + 2)
result = f(3)
assert f.calls == [call(3)]
Verify before relying
- Whether the package remains compatible with Python versions released after 2018 despite classifiers only listing up to 3.6
- Whether dormant status means the package will receive security updates if vulnerabilities are discovered
Package facts
| License | BSD (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 3,044 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 419,337/month — #6,799 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pretend-1.0.9-py2.py3-none-any.whl
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
flexmockflexmock creates mock, stub, spy, and fake…
permissive · top 15,000 on PyPI
stubsProvides a context-manager syntax for…
permissive · top 15,000 on PyPI
mockitoMockito is a spying and stubbing framework for…
permissive · top 5,000 on PyPI
pytest-stubA pytest plugin that replaces package, module,…
permissive · top 15,000 on PyPI
requests-mockIntercepts and mocks HTTP requests made through…
permissive · top 1,000 on PyPI
pytest-mockProvides a pytest fixture that wraps the mock…
permissive · top 1,000 on PyPI
placeboPlacebo records and replays AWS API calls…
permissive · top 15,000 on PyPI
urllib3-mockMocks urllib3 HTTP requests in tests by…
permissive · top 15,000 on PyPI
pyfakefspyfakefs mocks the Python file system modules…
permissive · top 5,000 on PyPI
pip-install-testA minimal stub package that verifies pip can…
permissive · top 15,000 on PyPI