Skip to main content

Non-alcoholic Mockito-style when-then utilities for unittest.mock

Project description

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

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

mocktail-0.0.3.tar.gz (3.2 kB view details)

Uploaded Source

File details

Details for the file mocktail-0.0.3.tar.gz.

File metadata

  • Download URL: mocktail-0.0.3.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for mocktail-0.0.3.tar.gz
Algorithm Hash digest
SHA256 f291f9abbb5078a597eba5f96dbca9b4575c41816e053cab5b64efb54c23b09f
MD5 baa076e8bc1d506e743020a11801dc05
BLAKE2b-256 f69a7e303633f20b91e5bc67deb95d5ee7919d61f79f40283d8b70bffddc2fa6

See more details on using hashes here.

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