Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mocktail

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mocktail

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

  • 0.0.4
  • PyPI
  • Socket score

Maintainers
1

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

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc