Welcome to Mockify!
About Mockify
Mockify is a highly customizable and expressive mocking library for Python inspired by Google Mock C++ framework, but adopted to Python world.
Unlike tools like unittest.mock
, Mockify is based on expectations
that you record on your mocks before they are injected to code being
under test. Each expectation represents arguments the mock is expected to be
called with and provides sequence of actions the mock will do when called
with that arguments. Actions allow to set a value to be returned, exception
to be raised or just function to be called. Alternatively, if no actions
should take place, you can just say how many times the mock is expected to be
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 invoke(func):
return func()
def test_invoke_calls_func_returning_hello_world():
func = Mock('func')
func.expect_call().will_once(Return('Hello, world!'))
with satisfied(func):
assert invoke(func) == 'Hello, world!'
I hope you’ll find this library useful.
User’s Guide
- Installation
- Quickstart
- Tutorial
- Tips & tricks
- API Reference
- mockify - Library core
- mockify.core - Library core
- mockify.mock - Classes for creating and inspecting mocks
- mockify.actions - Classes for recording side effects
- mockify.cardinality - Classes for setting expected call cardinality
- mockify.matchers - Classes for wildcarding expected arguments
- mockify.exc - Library exceptions
- mockify.abc - ABC classes for Mockify
- mockify.api - An all-in-one import module
- Changelog
- License