Skip to main content

A python mocking framework.

Project description

Pock is a mocking framework for python. Pock supports:

  • Creating magic mocks
  • Defining the behaviour of mocks
  • Asserting on the access of mocks

Pock does not make assumptions about which testing framework it’s being run inside, so it’ll work nicely with unittest, nosetest, pytest or whatever you choose to use.


pip install pock


Create a mock and add some basic behaviour:

from pock import mock, when, verify, any_value

my_mock = mock()
when(my_mock).greet('Andrew').then_return('Hi, Andrew')

my_mock.greet('Andrew')  # 'Hi, Andrew'

Assert on the access of the mock

verify(my_mock).greet('Andrew')  # True
verify(my_mock).greet('Someone else')  # VerificationError

Use matchers to be a little less specific

my_mock.start('pock')  # True
verify(my_mock).start(any_value)  # True

Mix and match exact values and matchers

when(my_mock).complex_call(1, 2, any_value, a=4, b=any_value)
my_mock.complex_call(1, 2, 3, a=4, b=5)  # None
verify(my_mock).complex_call(1, any_value, any_valuem a=any_value, b=any_value)

Raise exceptions on mock access

when(my_mock).connect('remotehost').then_raise(ConnectionError('Could not resolve host name'))
my_mock.connect('remotehost')  # ConnectionError

Mocking properties:

property_mock = mock()
property_mock.age  # 24
verify(property_mock).age  # True

Mocking top level functions:

function_mock = mock()
function_mock('c')  # 3
verify(fuction_mock)('c')  # True


pip install plank
plank install_requirements
plank tests



Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
pock-0.0.3.tar.gz (9.7 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page