Skip to main content

The property-based testing library for Python

Project description

Hypothesis

Hypothesis is the property-based testing library for Python. With Hypothesis, you write tests which should pass for all inputs in whatever range you describe, and let Hypothesis randomly choose which of those inputs to check - including edge cases you might not have thought about. For example:

from hypothesis import given, strategies as st


@given(st.lists(st.integers()))
def test_matches_builtin(ls):
    assert sorted(ls) == my_sort(ls)

This randomized testing can catch bugs and edge cases that you didn't think of and wouldn't have found. In addition, when Hypothesis does find a bug, it doesn't just report any failing example — it reports the simplest possible one. This makes property-based tests a powerful tool for debugging, as well as testing.

For instance,

def my_sort(ls):
    return sorted(set(ls))

fails with the simplest possible failing example:

Falsifying example: test_matches_builtin(ls=[0, 0])

Installation

To install Hypothesis:

pip install hypothesis

There are also optional extras available.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

hypothesis-6.153.6.tar.gz (475.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hypothesis-6.153.6-py3-none-any.whl (541.9 kB view details)

Uploaded Python 3

File details

Details for the file hypothesis-6.153.6.tar.gz.

File metadata

  • Download URL: hypothesis-6.153.6.tar.gz
  • Upload date:
  • Size: 475.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for hypothesis-6.153.6.tar.gz
Algorithm Hash digest
SHA256 8f7663251c57c9ee1fb6c0e919a6027cbda98d52b210dea441957d11d644c271
MD5 e729d555b8bc22d54ec4423acb00e692
BLAKE2b-256 e8c38c661bb893725eedeb003e85f3050274da2d77abf0847c4d61b4af53969c

See more details on using hashes here.

File details

Details for the file hypothesis-6.153.6-py3-none-any.whl.

File metadata

  • Download URL: hypothesis-6.153.6-py3-none-any.whl
  • Upload date:
  • Size: 541.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for hypothesis-6.153.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a892e3460e4dd8cfb8525682d8901be8f5e2d2c7b352359b71a44e5def2b89c8
MD5 a618948e2894d52c2705c5e16364515c
BLAKE2b-256 bf33f3ec54e6fb89c2279f0dd911ba512321e70038e447d1984c35fad61840f8

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