skillfed

stubs

Tools for setting up stubs and mocks.

stubs v1.0.0 92.5K downloads/30d#13,448 on PyPI1
Permissive license Apache 2.0 Abandoned released

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 stubs

uv

uv add stubs

poetry

poetry add stubs

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.4Programming Language :: Python :: 3.5

Tags

function stubbing context managermock functions with conditionstemporary function replacementstub testing pythonconditional function mockingmatcher-based stubstest double setup
abandonedlegacy-testing

More Testing packages