Skip to main content

Opinionated, typed stubbing and verification library for Python

Project description

Decoy

Opinionated, typed stubbing and verification library for Python

Usage guide and documentation

The Decoy library allows you to create, stub, and verify fully-typed, async/await friendly mocks in your Python unit tests, so your tests are:

  • Less prone to insufficient tests due to unconditional stubbing
  • Easier to fit into the Arrange-Act-Assert pattern
  • Covered by typechecking

The Decoy API is heavily inspired by / stolen from the excellent testdouble.js and Mockito projects.

Install

# pip
pip install decoy

# poetry
poetry add --dev decoy

Setup

Pytest setup

Decoy ships with its own pytest plugin, so once Decoy is installed, you're ready to start using it via its pytest fixture, called decoy.

# test_my_thing.py
from decoy import Decoy

def test_my_thing_works(decoy: Decoy) -> None:
    # ...

The decoy fixture is function-scoped and will ensure that all stub and spy state is reset between every test.

Mypy Setup

Decoy's API can be a bit confusing to mypy. To suppress mypy errors that may be emitted during valid usage of the Decoy API, we have a mypy plugin that you should add to your configuration file:

# mypi.ini

# ...
plugins = decoy.mypy
# ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

decoy-1.5.0.tar.gz (12.4 kB view hashes)

Uploaded Source

Built Distribution

decoy-1.5.0-py3-none-any.whl (14.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page