Skip to main content

A Python Mocking and Patching Library for Testing

Project description

There are already several Python mocking libraries available, so why another one?

Most mocking libraries follow the ‘record -> replay’ pattern of mocking. I prefer the ‘action -> assertion’ pattern, which is more readable and intuitive particularly when working with the Python unittest module. For a discussion of the merits of the two approaches, see Mocking, Patching, Stubbing: all that Stuff.

mock provides a core Mock class that is intended to reduce the need to create a host of trivial stubs throughout your test suite. After performing an action, you can make assertions about which methods / attributes were used and arguments they were called with. You can also specify return values and set specific attributes in the normal way.

It also provides a patch decorator that handles patching module and class level attributes within the scope of a test, along with sentinel for creating unique objects.

Project details


Download files

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

Source Distribution

mock-0.5.0.tar.gz (21.2 kB view details)

Uploaded Source

File details

Details for the file mock-0.5.0.tar.gz.

File metadata

  • Download URL: mock-0.5.0.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mock-0.5.0.tar.gz
Algorithm Hash digest
SHA256 82a3a60c6ce832d0b799d33924dc40d766e95e2481f8758e8eafafc524b63531
MD5 329fafdc91c83eab608ca80c8bb490f9
BLAKE2b-256 6c442b50aa4a4146e27642fded9baf81a49d430c8b134d31e694e2d78c33aeed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page