Skip to main content
Help us improve Python packaging – donate today!

A mocking framework for Python

Project Description

Funk is a mocking framework for Python, influenced heavily by JMock. Funk helps to test modules in isolation by allowing mock objects to be used in place of “real” objects. Funk is licensed under the 2-clause BSD licence.


$ pip install funk


Let’s say we have a TagRepository class, which has a fetch_all method on it. This method will fetch all instances of Tag from the database for us.

We also have a class that we’d like to test, called TagDisplayer. Its constructor takes a TagRepository, and has a method display_all. We want to test that this method will grab all of the tags from the repository, sort them into alphabetical order, and write their names into a string separated by new lines.

from import assert_equals
import funk
from funk import expects

def test_writes_all_tag_names_onto_separate_lines(mocks):
    tag_repository = mocks.mock(TagRepository)

        .returns([Tag('python'), Tag('debian')])

    tag_displayer = TagDisplayer(tag_repository)
    assert_equals(tag_displayer.display_all(), 'python\ndebian')

By using a mock object instead of a real instance of TagRepository, we avoid relying on a correct implementation of TagRepository. We can also run the test without a running database.

Release history Release notifications

This version
History Node


History Node


History Node


History Node


History Node


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
Funk-0.4.0.tar.gz (220.0 kB) Copy SHA256 hash SHA256 Source None Jan 14, 2014

Supported by

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