skillfed

pretend

A library for stubbing in Python

pretend v1.0.9 419.3K downloads/30d#6,799 on PyPI318
Permissive license BSD DORMANT released

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 pretend

uv

uv add pretend

poetry

poetry add pretend

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: Python :: 2.6Programming Language :: Python :: 2.7Programming Language :: Python :: 3.2Programming Language :: Python :: 3.3Programming Language :: Python :: 3.4Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Topic :: Software Development :: Testing

Tags

python stubbing librarytest stub objectsmock alternativeslightweight test doublesstub creation testingcall recording test utilitypre-canned responses testing
test-doublesstubbing

More Testing packages