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

Uploaded Source

Built Distribution

hypothesis-6.138.2-py3-none-any.whl (530.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for hypothesis-6.138.2.tar.gz
Algorithm Hash digest
SHA256 82e3b2ac709ee3edda4aba2f4b11becfe764f51d104fcdb3e9f95aff1ac81595
MD5 144fe2d633160b88ec833584f95484d7
BLAKE2b-256 7d6d68b8f1468da10dab5e903f6278cdfe88e05631a23009b2d9bf75b23e63f1

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for hypothesis-6.138.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2886c5e7569437781d1dc42973021f70f7facb7e410249dcb899b0edb249e5b8
MD5 a95da7b40ef827eef3a7ef61a3d0305f
BLAKE2b-256 a1ab012b126e5be088b8de28a6f7eed2cf71b7c009233d9cd3f730419fda22ae

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