Opinionated, typed stubbing and verification library for Python
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.