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.3.tar.gz (474.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.3-py3-none-any.whl (540.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hypothesis-6.153.3.tar.gz
  • Upload date:
  • Size: 474.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.3.tar.gz
Algorithm Hash digest
SHA256 112ce43df0cae69cce3578f1f33523ae6ae730b4d9a224ac508d331428bb44d6
MD5 e902505965c96f79552766874355ad4f
BLAKE2b-256 f1dd757c87497c66868d83328be245b4bc9e952617073de02c48aca0fb1d6096

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hypothesis-6.153.3-py3-none-any.whl
  • Upload date:
  • Size: 540.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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 016c96a1a102d682faf2f85706ea51cbe2f8c20f2d252e8cdc3710ed9d8da1f2
MD5 0045f6eb2c0f3a35d1496030e0b10200
BLAKE2b-256 00ad0a550b63e017d4032d343be6465d216a8d36f6ccad4f6577b08de335cb00

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