#4882·hypothesis

Ghostwriter writes @given() for functions with no parameters

Author: ZacKienzle2Created Sep 25, 2026Updated Sep 25, 2026

Reproduced with hypothesis 6.168.1, Python 3.13, Windows 11.

python
# dice3.py
from fractions import Fraction
from itertools import product


def expected_max_enumerated() -> Fraction:
    outcomes = list(product(range(1, 7), repeat=3))
    return Fraction(sum(max(o) for o in outcomes), len(outcomes))


def expected_max_closed_form() -> Fraction:
    return sum((1 - Fraction(k, 6) ** 3 for k in range(6)), Fraction(0))

hypothesis write --style=pytest --equivalent dice3.expected_max_enumerated dice3.expected_max_closed_form prints:

python
import dice3
from hypothesis import given, strategies as st


@given()
def test_equivalent_expected_max_enumerated_expected_max_closed_form():
    result_expected_max_enumerated = dice3.expected_max_enumerated()
    result_expected_max_closed_form = dice3.expected_max_closed_form()
    assert result_expected_max_enumerated == result_expected_max_closed_form, (
        result_expected_max_enumerated,
        result_expected_max_closed_form,
    )

Running it fails with hypothesis.errors.InvalidArgument: given must be called with at least one argument.

Expected: when the functions take no arguments there is nothing to generate, so the ghostwriter could write a plain test without @given that calls each function and compares the results.

Source: HypothesisWorks/hypothesis