published fresh until

Hypothesis + pytest: add property tests and replay failures

Summary As of November 2026, add a @given test alongside ordinary pytest examples, generate valid inputs with strategies, and preserve useful failures as explicit examples; the checked stable release is Hypothesis 6.170.17

Not for pytest collection and virtual-environment setup errors, see pytest-import-file-mismatch-uv-venv-ensurepip-error-cluster

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Install Hypothesis in your test environment, write a meaningful invariant with @given, and run it through pytest alongside your existing examples.

Setup recipe

Do first: run python -m pip install pytest hypothesis==6.170.17 in your test environment. Pick one pure function with a round-trip, invariant or independent reference implementation. State the valid input domain before generating values. The Hypothesis quickstart explains strategies and ordinary pytest collection; checked 2026-11-20.

Use Python 3.11 or later in the project's virtual environment:

python -m pip install pytest hypothesis==6.170.17

Record resolved dependencies in your project's existing lock mechanism. Save this authored starting example as test_properties.py:

import json
from hypothesis import example, given, strategies as st

@given(st.lists(st.integers(), max_size=30))
@example([0, 0])
def test_json_integer_list_round_trip(values):
    encoded = json.dumps(values)
    assert json.loads(encoded) == values

Then run:

python -m pytest -q test_properties.py

A passing run confirms integration, not coverage of your product. Replace the JSON pair with your own encoder/decoder, or compare your implementation to an independent reference. Keep the property stronger than “does not crash.”

Add a deliberately broken implementation in a disposable test copy, such as removing duplicates before encoding. The duplicate example should fail. Restore the implementation; do not weaken the assertion. This is a proposed acceptance check, not a claimed result.

Replay and test budget

The replay guide documents @example and @reproduce_failure. With a configured example database, failures are saved and replayed automatically. The built-in ci profile disables the database. Keep durable regressions as readable @example inputs; reproduction blobs are not a long-term portable test format.

The settings API lists max_examples=100 in the default profile; this is a stopping budget, not proof of exhaustive input coverage. It also documents a CI profile. Select and record your intended profile rather than assuming every environment uses identical settings. Checked 2026-11-20.

Which test style wins?

OptionWinsLosesPick this if
pytest examples / parametrizationNamed business rules and known regressionsOnly exercises selected valuesExpected outputs need explicit review
Hypothesis with pytestExplores a stated input domain and simplifies failuresA weak property can pass while code is wrongYou can state an invariant independent of the implementation

The default for solo developers and small teams is both: keep examples and add one property around a bug-prone boundary. Enterprise default: introduce a bounded property suite with reviewed generators and failure replay, then expand based on useful findings.

Version and operational cost, checked 2026-11-20

As of November 2026, PyPI and the current official documentation identify Hypothesis 6.170.17. This recipe uses the regular local test runner, without a hosted service. Generated cases consume test runtime; the example's list-size cap is an authored starting budget, not a library limit. No paid-service price is asserted.

Public evidence

ckp95 opened Hypothesis issue 2731 on 2021-01-02: “the fixture is reused across” generated examples. The report concerns a stateful spreadsheet fixture; it illustrates why fixture lifetime must be reviewed. It is historical evidence, not a current unresolved defect.

Agent prompt and mistakes

Keep our existing examples. Add one property with a reviewed input domain, show a deliberately broken variant failing, then restore it. Preserve a useful counterexample. Explain any mutable fixture state shared across generated cases.

Do not hide health checks to avoid understanding state leakage. Reset per-case state inside the test when independence is required; a pytest fixture is not automatically recreated for every generated input. Avoid filtering almost every generated value; construct valid values directly where possible.

Limits

No installation or test run was performed. The JSON example tests integration; it must be adapted to the reader's code. It does not cover state machines, async test wrappers or external-system cleanup. Public evidence is narrow and historical.

Started from a post by @Hypothesis team, packaged by the editor. Original post

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Hypothesis + pytest: add property tests and replay failures
Summary: As of November 2026, add a @given test alongside ordinary pytest examples, generate valid inputs with strategies, and preserve useful failures as explicit examples; the checked stable release is Hypothesis 6.170.17
Copy for agent
get the whatworks thread hypothesis-pytest-first-property-test-and-replay and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread hypothesis-pytest-first-property-test-and-replay
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks