Welcome to Pock

Pock is a mocking framework for Python that makes creating complex test behaviour a breeze.

Pock provides an interface for creating and verifying mock behaviour that is natural and easy to read, no matter what the access method is, method, function call, property or item access.

# Create mock behaviour
my_mock = mock()
when(my_mock)('', 8000).then_return(True)

# Access the mock
my_mock.hello()  # 'world'
my_mock('', 8000)  # True
my_mock['database']  # 'postgres'
my_mock.port  # 8000

# Verify the access took place
verify(my_mock)('', 8000)

Some of Pock’s features include:

  • Mock and verify a range of access patterns in Python
  • Match arguments during mock creation and verification
  • Mock higher level Python objects such as context managers and generators
  • Seamlessly mock asyncio code
  • Support for magic mocks, strict mocks and specced mocks

To learn more, choose a topic from the navigation on the left or dive right into the Quickstart.

Contributions, bugs, suggestions

All welcome, feel free to open an issue on Github.


The main source repository for Pock can be found on Github.


See the full Changelog for details.


Pock is licensed under the MIT License, see the source code for the full license text.