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).hello().then_return('world')
when(my_mock)('127.0.0.1', 8000).then_return(True)
when(my_mock)['database'].then_return('postgres')
when(my_mock).port.then_return(8000)
# Access the mock
my_mock.hello() # 'world'
my_mock('127.0.0.1', 8000) # True
my_mock['database'] # 'postgres'
my_mock.port # 8000
# Verify the access took place
verify(my_mock).hello()
verify(my_mock)('127.0.0.1', 8000)
verify(my_mock)['database']
verify(my_mock).port
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.
License¶
Pock is licensed under the MIT License, see the source code for the full license text.