Skip to content

Overview

banner

flexmock - Mock, stub, and spy library for Python.

pypi ci documentation codecov license


Contribute: https://github.com/flexmock/flexmock
Download: https://pypi.python.org/pypi/flexmock


Flexmock is a testing library for Python.

Its API is inspired by a Ruby library of the same name. However, it is not a goal of Python flexmock to be a clone of the Ruby version. Instead, the focus is on providing full support for testing Python programs and making the creation of fake objects as unobtrusive as possible.

As a result, Python flexmock removes a number of redundancies in the Ruby flexmock API, alters some defaults, and introduces several Python-only features.

Flexmock's design focuses on simplicity and intuitiveness. This means that the API is as lean as possible, though a few convenient short-hand methods are provided to aid brevity and readability.

Flexmock declarations are structured to read more like English sentences than API calls, and it is possible to chain them together in any order to achieve a high degree of expressiveness in a single line of code.

Installation

Install with pip:

pip install flexmock

Compatibility

Tested to work with:

  • Python 3.8
  • Python 3.9
  • Python 3.10
  • Python 3.12
  • Python 3.13
  • PyPy3

Automatically integrates with all major test runners, including:

  • unittest
  • pytest
  • django
  • twisted / trial
  • doctest
  • zope.testrunner
  • subunit
  • testtools