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.2.tar.gz (3.1 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: mocktail-0.0.2.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0

File hashes

Hashes for mocktail-0.0.2.tar.gz
Algorithm Hash digest
SHA256 3c745608fbcd74e2c546b613dce7a928abbb399bb8ca4fa344937c42a7772198
MD5 b1a5ece1facfeb479ffed23ed3dcc2c5
BLAKE2b-256 0ddf6c9bb5b35c14b138c60f33ad941fb1f8525704e4cf1a801f243d4096622c

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