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

Uploaded Source

Built Distribution

hypothesis-6.135.31-py3-none-any.whl (522.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for hypothesis-6.135.31.tar.gz
Algorithm Hash digest
SHA256 a759a6010a43424b66b634383a04717a30ed05f553cc51e3b3fe3931faace53a
MD5 1f5f1165bb98b0f34c2a2c5a5748267e
BLAKE2b-256 222c988c75a27f805ce53ef5a3feaf96add76fe93aede509e16126408c426a0d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hypothesis-6.135.31-py3-none-any.whl
  • Upload date:
  • Size: 522.8 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.135.31-py3-none-any.whl
Algorithm Hash digest
SHA256 12f1cf4aa961884b71021ef8770d81045f66c0b3f4295abc956e4f84d862f321
MD5 15bb2c9a23e09a9bd4869940d6fd280d
BLAKE2b-256 08f63a9ad54d87c3bc5d4fe4925b0eb5d93c5e3090cf6fe8472176651ce04eea

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