python-hypothesis

Generate property-based tests with Hypothesis strategies that model valid input spaces.

1|2|Updated Nov 25, 2017
One-click install
npx skills add https://github.com/asarchami/dotfiles --skill python-hypothesis-asarchami
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-hypothesis
Source: https://github.com/asarchami/dotfiles/tree/main/dot_config/opencode/skills/python/hypothesis
Command: npx skills add https://github.com/asarchami/dotfiles --skill python-hypothesis-asarchami

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires hypothesis.

What problem does it solve? Writing thorough unit tests by hand often misses edge cases, and example-based tests only cover the inputs you think of. This Skill reads your production code and generates Hypothesis property-based tests that systematically explore the valid input space of each function. ## Core Features & Use Cases - Strategy Design: Builds reusable input strategies in tests/strategies.py using st.builds(), @st.composite, and st.register_type_strategy, encoding constraints directly instead of filtering. - Property-Focused Tests: Writes minimal tests targeting behavioural contracts such as roundtrips, idempotence, invariant preservation, and equivalence to reference implementations. - Use Case: Point the Skill at a module with complex parsing logic and no tests; it reads the functions, designs strategies matching their valid inputs, and produces a test suite that catches edge-case bugs automatically. ## Quick Start Ask the agent to generate Hypothesis property-based tests for the functions in my parser module.

Frequently Asked Questions about python-hypothesis

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write property-based tests with Hypothesis in Python?▼

Define input strategies with hypothesis.strategies, then use the @given decorator to feed generated values into test functions. Assert behavioural properties like roundtrips or invariants rather than specific example outputs.

How do I create Hypothesis strategies for custom types?▼

Use st.builds() for simple constructors and @st.composite for objects with dependent fields. Register them with st.register_type_strategy so st.from_type resolves your type automatically.

Should I filter Hypothesis strategies to get valid inputs?▼

No, prefer encoding constraints directly, such as st.integers(min_value=1), instead of st.integers().filter(...). Filtering slows generation and can cause Hypothesis to fail finding valid examples.

What properties should I test with Hypothesis?▼

Test behavioural contracts: roundtrip or inverse properties, idempotence, invariant preservation, and equivalence to a reference implementation. Avoid structural trivia, reimplementing the function, or testing glue code.

When is property-based testing not a good fit?▼

It adds little value for functions that are just glue code, tests of side effects tied to the current implementation, or checks of structural trivia like output schema keys. Example-based tests suit those cases better.