/hypothesis-testing
Property-based testing with Hypothesis for discovering edge cases and validating invariants. Use when implementing comprehensive test coverage, testing complex logic with many inputs, or validating mathematical properties and invariants across input domains. Triggered by:
$ npx -y skills add foryourhealth111-pixel/Vibe-Skills --skill hypothesis-testing --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/hypothesis-testing
Context preview
The summary Claude sees to decide when to auto-load this skill.
Property-based testing with Hypothesis for discovering edge cases and validating invariants. Use when implementing comprehensive test coverage, testing complex logic with many inputs, or validating mathematical properties and invariants across input domains. Triggered by:
SKILL.md
hypothesis-testing.SKILL.mdcreated: 2025-12-16
modified: 2025-12-16
reviewed: 2025-12-16
name: hypothesis-testing
description: |
Property-based testing with Hypothesis for discovering edge cases and validating invariants.
Use when implementing comprehensive test coverage, testing complex logic with many inputs,
or validating mathematical properties and invariants across input domains.
Triggered by: hypothesis, property-based testing, @given, strategies, generative testing.
Hypothesis Property-Based Testing
Hypothesis is a powerful property-based testing library that automatically generates test cases to find edge cases and validate properties of your code.
Core Concept
**Traditional example-based testing:**
def test_addition():
assert add(2, 3) == 5
assert add(0, 0) == 0
assert add(-1, 1) == 0**Property-based testing with Hypothesis:**
from hypothesis import given
import hypothesis.strategies as st
@given(st.integers(), st.integers())
def test_addition_commutative(a, b):
"""Addition is commutative for ALL integers."""
assert add(a, b) == add(b, a)Hypothesis generates hundreds of test cases automatically, including edge cases you might not think of.
Installation
# Install hypothesis with pytest integration
uv add --dev hypothesis pytest
# Optional plugins
uv add --dev hypothesis[numpy] # NumPy strategies
uv add --dev hypothesis[pandas] # Pandas strategies
uv add --dev hypothesis[django] # Django model strategies
Configuration
pyproject.toml Configuration
[tool.pytest.ini_options]
# Hypothesis settings
addopts = [
"--hypothesis-show-statistics", # Show test statistics
"--hypothesis-seed=0", # Reproducible tests (optional)
]
[tool.hypothesis]
# Maximum number of examples to generate
max_examples = 200 # Default: 100, CI: 200+
# Deadline for each test case (milliseconds)
deadline = 1000 # Default: 200ms, None to disable
# Verbosity level (quiet, normal, verbose, debug)
verbosity = "normal"
# Fail fast on first error
derandomize = false # Set to true for deterministic tests
# Database for example storage
database = ".hypothesis/examples" # Store found failures
# Profile-specific settings
[tool.hypothesis.profiles.dev]
max_examples = 50
deadline = 1000
verbosity = "normal"
[tool.hypothesis.profiles.ci]
max_examples = 500
deadline = 5000
verbosity = "verbose"
[tool.hypothesis.profiles.debug]
max_examples = 10
deadline = null
verbosity = "debug"Activate Profile
# tests/conftest.py
from hypothesis import settings, Verbosity
# Set default profile based on environment
import os
if os.getenv("CI"):
settings.load_profile("ci")
else:
settings.load_profile("dev")
# Or configure programmatically
settings.register_profile("custom", max_examples=100, deadline=500)
settings.load_profile("custom")Basic Usage
Simple Property Tests
from hypothesis import given, example
import hypothesis.strategies as st
# Test numeric properties
@given(st.integers())
def test_absolute_value_non_negative(x):
"""abs(x) is always non-negative."""
assert abs(x) >= 0
@given(st.integers(), st.integers())
def test_addition_associative(a, b, c):
"""Addition is associative: (a + b) + c == a + (b + c)."""
assert (a + b) + c == a + (b + c)
# Test string properties
@given(st.text())
def test_string_length(s):
"""Length of reversed string equals original."""
assert len(s[::-1]) == len(s)
@given(st.text(), st.text())
def test_string_concatenation(s1, s2):
"""String concatenation length is sum of lengths."""
result = s1 + s2
assert len(result) == len(s1) + len(s2)
# Add explicit examples alongside generated ones
@given(st.integers())
@example(0)
@example(-1)
@example(2**31 - 1)
def test_with_explicit_examples(x):
"""Test with both generated and explicit examples."""
assert process(x) is not NoneTesting Functions
from hypothesis import given, assume
import hypothesis.strategies as st
def safe_divide(a: float, b: float) -> float:
"""Divide a by b, avoiding division by zero."""
if b == 0:
raise ValueError("Division by zero")
return a / b
@given(st.floats(allow_nan=False, allow_infinity=False),
st.floats(allow_nan=False, allow_infinity=False))
def test_safe_divide(a, b):
"""Test safe_divide with all valid floats."""
assume(b != 0) # Skip cases where b is zero
result = safe_divide(a, b)
# Properties to verify
assert isinstance(result, float)
assert result * b == pytest.approx(a) # Inverse operation
@given(st.floats())
def test_divide_by_zero_raises(a):
"""Division by zero raises ValueError."""
with pytest.raises(ValueError, match="Division by zero"):
safe_divide(a, 0)Strategies
Built-in Strategies
import hypothesis.strategies as st
# Primitives
st.none() # None
st.booleans() # True/False
st.integers() # Any integer
st.integers(min_value=0, max_value=100) # Bounded integers
st.floats() # Any float
st.floats(min_value=0.0, max_value=1.0) # Bounded floats
st.decimals() # Decimal numbers
st.fractions() # Fraction objects
st.complex_numbers() # Complex numbers
# Text and bytes
st.text() # Unicode strings
st.text(alphabet="abc") # Limited alphabet
st.text(min_size=1, max_size=10) # Bounded length
st.binary() # Bytes
st.characters() # Single characters
# Collections
st.lists(st.integers()) # Lists of integers
st.lists(st.text(), min_size=1, max_size=10) # Bounded lists
st.tuples(st.integers(), st.text()) # Fixed-size tuples
st.sets(st.integers()) # Sets
st.frozensets(st.text()) # Frozen sets
st.dictionaries(keys=st.text(), values=st.integers()) # Dicts
# Special types
st.uuids() # UUID objects
st.datetimes
Read more
created: 2025-12-16 modified: 2025-12-16 reviewed: 2025-12-16 name: hypothesis-testing description: | Property-based testing with Hypothesis for discovering edge cases and validating invariants. Use when implementing comprehensive test coverage, testing complex logic with many inputs, or validating mathematical properties and invariants across input domains. Triggered by: hypothesis, property-based testing, @given, strategies, generative testing.
Hypothesis Property-Based Testing
Hypothesis is a powerful property-based testing library that automatically generates test cases to find edge cases and validate properties of your code.
Core Concept
**Traditional example-based testing:**
def test_addition():
assert add(2, 3) == 5
assert add(0, 0) == 0
assert add(-1, 1) == 0**Property-based testing with Hypothesis:**
from hypothesis import given
import hypothesis.strategies as st
@given(st.integers(), st.integers())
def test_addition_commutative(a, b):
"""Addition is commutative for ALL integers."""
assert add(a, b) == add(b, a)Hypothesis generates hundreds of test cases automatically, including edge cases you might not think of.
Installation
# Install hypothesis with pytest integration uv add --dev hypothesis pytest # Optional plugins uv add --dev hypothesis[numpy] # NumPy strategies uv add --dev hypothesis[pandas] # Pandas strategies uv add --dev hypothesis[django] # Django model strategies
Configuration
pyproject.toml Configuration
[tool.pytest.ini_options]
# Hypothesis settings
addopts = [
"--hypothesis-show-statistics", # Show test statistics
"--hypothesis-seed=0", # Reproducible tests (optional)
]
[tool.hypothesis]
# Maximum number of examples to generate
max_examples = 200 # Default: 100, CI: 200+
# Deadline for each test case (milliseconds)
deadline = 1000 # Default: 200ms, None to disable
# Verbosity level (quiet, normal, verbose, debug)
verbosity = "normal"
# Fail fast on first error
derandomize = false # Set to true for deterministic tests
# Database for example storage
database = ".hypothesis/examples" # Store found failures
# Profile-specific settings
[tool.hypothesis.profiles.dev]
max_examples = 50
deadline = 1000
verbosity = "normal"
[tool.hypothesis.profiles.ci]
max_examples = 500
deadline = 5000
verbosity = "verbose"
[tool.hypothesis.profiles.debug]
max_examples = 10
deadline = null
verbosity = "debug"Activate Profile
# tests/conftest.py
from hypothesis import settings, Verbosity
# Set default profile based on environment
import os
if os.getenv("CI"):
settings.load_profile("ci")
else:
settings.load_profile("dev")
# Or configure programmatically
settings.register_profile("custom", max_examples=100, deadline=500)
settings.load_profile("custom")Basic Usage
Simple Property Tests
from hypothesis import given, example
import hypothesis.strategies as st
# Test numeric properties
@given(st.integers())
def test_absolute_value_non_negative(x):
"""abs(x) is always non-negative."""
assert abs(x) >= 0
@given(st.integers(), st.integers())
def test_addition_associative(a, b, c):
"""Addition is associative: (a + b) + c == a + (b + c)."""
assert (a + b) + c == a + (b + c)
# Test string properties
@given(st.text())
def test_string_length(s):
"""Length of reversed string equals original."""
assert len(s[::-1]) == len(s)
@given(st.text(), st.text())
def test_string_concatenation(s1, s2):
"""String concatenation length is sum of lengths."""
result = s1 + s2
assert len(result) == len(s1) + len(s2)
# Add explicit examples alongside generated ones
@given(st.integers())
@example(0)
@example(-1)
@example(2**31 - 1)
def test_with_explicit_examples(x):
"""Test with both generated and explicit examples."""
assert process(x) is not NoneTesting Functions
from hypothesis import given, assume
import hypothesis.strategies as st
def safe_divide(a: float, b: float) -> float:
"""Divide a by b, avoiding division by zero."""
if b == 0:
raise ValueError("Division by zero")
return a / b
@given(st.floats(allow_nan=False, allow_infinity=False),
st.floats(allow_nan=False, allow_infinity=False))
def test_safe_divide(a, b):
"""Test safe_divide with all valid floats."""
assume(b != 0) # Skip cases where b is zero
result = safe_divide(a, b)
# Properties to verify
assert isinstance(result, float)
assert result * b == pytest.approx(a) # Inverse operation
@given(st.floats())
def test_divide_by_zero_raises(a):
"""Division by zero raises ValueError."""
with pytest.raises(ValueError, match="Division by zero"):
safe_divide(a, 0)Strategies
Built-in Strategies
import hypothesis.strategies as st # Primitives st.none() # None st.booleans() # True/False st.integers() # Any integer st.integers(min_value=0, max_value=100) # Bounded integers st.floats() # Any float st.floats(min_value=0.0, max_value=1.0) # Bounded floats st.decimals() # Decimal numbers st.fractions() # Fraction objects st.complex_numbers() # Complex numbers # Text and bytes st.text() # Unicode strings st.text(alphabet="abc") # Limited alphabet st.text(min_size=1, max_size=10) # Bounded length st.binary() # Bytes st.characters() # Single characters # Collections st.lists(st.integers()) # Lists of integers st.lists(st.text(), min_size=1, max_size=10) # Bounded lists st.tuples(st.integers(), st.text()) # Fixed-size tuples st.sets(st.integers()) # Sets st.frozensets(st.text()) # Frozen sets st.dictionaries(keys=st.text(), values=st.integers()) # Dicts # Special types st.uuids() # UUID objects st.datetimes
VibeSkills is a general-purpose Skill that automatically routes local Skills and intelligently orchestrates harness workflows.
Repo: foryourhealth111-pixel/Vibe-Skills
Other skills on vibe-skills.
- /LQF_Machine_Learning_Expert_Guide
LQF Machine Learning Expert Guide - Routed skill for ML/Statistical Modeling with Critical Discussion Mode. Triggers on: machine learning, modeling, prediction, training, classification, regression, clustering, deep learning, neural network, model evaluation, feature
Open skill - /adaptyv
Cloud laboratory platform for automated protein testing and validation. Use when designing proteins and needing experimental validation including binding assays, expression testing, thermostability measurements, enzyme activity assays, or protein sequence optimization. Also use
Open skill - /aeon
This skill should be used for time series machine learning tasks including classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search. Use when working with temporal data, sequential patterns, or time-indexed observations
Open skill - /algorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing
Open skill - /alpha-vantage
Access real-time and historical stock market data, forex rates, cryptocurrency prices, commodities, economic indicators, and 50+ technical indicators via the Alpha Vantage API. Use when fetching stock prices (OHLCV), company fundamentals (income statement, balance sheet, cash
Open skill - /architecture-patterns
Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use when architecting complex backend systems or refactoring existing applications for better maintainability.
Open skill
