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.151.14.tar.gz (464.4 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.151.14-py3-none-any.whl (530.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hypothesis-6.151.14.tar.gz
  • Upload date:
  • Size: 464.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for hypothesis-6.151.14.tar.gz
Algorithm Hash digest
SHA256 14fffdfdb50e816cf114f9946aebbf533d7e0920c07ddc1531889f0a22ffaa20
MD5 daf1203dc9407edf8ed113589c8e2ef8
BLAKE2b-256 83773227982784ff12a74fc5b28823f3487f457640e6cc653afe16d090891334

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hypothesis-6.151.14-py3-none-any.whl
  • Upload date:
  • Size: 530.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for hypothesis-6.151.14-py3-none-any.whl
Algorithm Hash digest
SHA256 0c27a1e1092752d8c424b7f1caeb6ecfbed9af87914f510b59c1be69945e85a5
MD5 d7f5f6588c066f3a34b2f98c1c788f7c
BLAKE2b-256 b7601d19db13777148efb57c27a8ceea48afb80cba9ce6da85b57ccbe0e8f44f

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