Skip to main content

A library for property-based testing

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.135.10.tar.gz (452.5 kB view details)

Uploaded Source

Built Distribution

hypothesis-6.135.10-py3-none-any.whl (518.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hypothesis-6.135.10.tar.gz
  • Upload date:
  • Size: 452.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for hypothesis-6.135.10.tar.gz
Algorithm Hash digest
SHA256 ce224e310012e40b8e3aa6edba226c032c57bbcbdccad41212ab6d2d74b602cf
MD5 500decfc7923b2154d2ab7519e765761
BLAKE2b-256 c88e6176e9b3e51fbab6dab1e572116605dbc54eadda0c60dd45927f601d3c60

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hypothesis-6.135.10-py3-none-any.whl
  • Upload date:
  • Size: 518.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for hypothesis-6.135.10-py3-none-any.whl
Algorithm Hash digest
SHA256 275012ee9a7a1a64fd38745c2b7a07e838fc9f738d49c97a881d235b53fe28c1
MD5 7c150bd625b4b59cfc3f8004b73dba1a
BLAKE2b-256 a9e58c62bd37d2815f37a2886be6b9d5e037d14cc3f6adc377711f323617b113

See more details on using hashes here.

Supported by

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