Skip to main content

Mocking library for Python inspired by Google Mock C++ mocking toolkit

Project description

PyPI - License PyPI PyPI - Downloads codecov

Mockify

Highly customizable and expressive mocking library for Python.

About

Mockify is a library inspired by Google Mock C++ framework, but adopted to Python world.

Mockify is based on expectations that you need to record on your mocks before those are called by code you're testing. And expectations you're recording are basically assertions that must pass before test ends. Along with expectations you can also record actions the mock will execute once called. And all of these is provided by simple, expressive and easy to use API.

Here's a simple example:

from mockify.core import satisfied
from mockify.mock import Mock
from mockify.actions import Return

def func_caller(func):
    return func()

def test_func_caller():
    func_mock = Mock('greet')
    func_mock.expect_call().will_once(Return('Hello, world!'))
    with satisfied(func_mock):
        assert func_caller(func_mock) == 'Hello, world!'

Mockify allows you to:

  • Record expectations with any number of positional and/or keyword arguments,
  • Set expected call count or call count range,
  • Record action chains, allowing subsequent action can be performed on subsequent call to same mock,
  • Record repeated actions that can be executed any number of times,
  • Use matchers, allowing to match range of parameters the mock is called with instead of exact ones,
  • and more.

I hope you'll find this library useful.

Documentation

Newest documentation can be found at https://mockify.readthedocs.org/.

Source

Source code is available at https://gitlab.com/zef1r/mockify/.

License

This software is released under the terms of the MIT license.

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

mockify-0.11.0.tar.gz (75.8 kB view details)

Uploaded Source

Built Distribution

mockify-0.11.0-py3-none-any.whl (37.5 kB view details)

Uploaded Python 3

File details

Details for the file mockify-0.11.0.tar.gz.

File metadata

  • Download URL: mockify-0.11.0.tar.gz
  • Upload date:
  • Size: 75.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.9

File hashes

Hashes for mockify-0.11.0.tar.gz
Algorithm Hash digest
SHA256 f47d90b8877ee37fee2940a0ffd13f46d5211e66a7de01a2d5ad59f544fe25f0
MD5 06c56093250b61a03be555d43310a851
BLAKE2b-256 b9b980dd54f58e0f8bb1f622f9b075173c527d20b74f91757151547b111ff73d

See more details on using hashes here.

Provenance

File details

Details for the file mockify-0.11.0-py3-none-any.whl.

File metadata

  • Download URL: mockify-0.11.0-py3-none-any.whl
  • Upload date:
  • Size: 37.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.9

File hashes

Hashes for mockify-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 19deaf26e257f2a6bc9e048ea0913aced6d3b5ccf5d0c26257c627f1766b75f0
MD5 4941c85b0d6142db7750963df3f63e66
BLAKE2b-256 f998b05c3b6011c7d6015c660451fdde7867c2b5ed58611d81dbf2ec233f2e68

See more details on using hashes here.

Provenance

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