Skip to main content

Mocktail

The non-alcoholic, Mockito-inspired utility for unittest.mock!

Build Status

This package provides dead-simple utilities for setting return values for mocks with a Mockito-inspired syntax:

from unittest.mock import MagicMock
from mocktail import when

my_mock = MagicMock()
when(my_mock).some_method('foo').then_return('bar')

my_mock.some_method('foo')  # 'bar'

Unlike other solutions (like mockito-python), it deliberately only works with mocks created using unittest.mock. To set the return values of arbitrary objects, combine with unittest.mock.patch.

Installation

pip install mocktail

Buyer beware!

This package -- though very minimal -- is in early alpha stage. Use with your own risk!

Contributing

Pull requests and bug reports are gladly accepted in this Github repository.

License

MIT

TODO

  • (More) matchers
  • Matcher for "rest of args / kwargs"
  • verify syntax
  • Docs
  • Some way to make "missed" matches more explicit, ie. raising an error e.g. when(...).foo(...).then_return(...).raise_missing() or when(..., raise_missing=True).foo(...).then_return(...)
  • Refactor the logic when hooking multiple then_returns for call proxies. Currently, it should work because existing side_effect is called, but it's a bit hairy
  • The matcher interface could be removed and instead we could just overwrite __eq__ for matchers

Metadata

Release files for mocktail 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mocktail 0.0.4
File Size Uploaded Provenance Actions
mocktail-0.0.4.tar.gz 3.6 kB Without provenance Details for mocktail-0.0.4.tar.gz

Release files / mocktail-0.0.4.tar.gz

Download URL mocktail-0.0.4.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
fd11f32ef0b846c553c5c7c11f624dcacb3c058a0537968cf31b97d195e5f311
BLAKE2b-256 checksum
How to use checksums
a9730682c5e0e35282e242b155279bc908fe1bdb0adfbc6a658db4fff751bd9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.3

Security for mocktail 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page