Skip to content

gh-107862: Add stateful, timezones and ip_addresses to the Hypothesis stubs - #159770

Merged
pganssle merged 2 commits into
python:mainfrom
pganssle:hypothesis-stubs-stateful
Oct 20, 2026
Merged

pganssle merged 2 commits into
python:mainfrom
pganssle:hypothesis-stubs-stateful

Conversation

@pganssle

@pganssle pganssle commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

The stubs in test.support._hypothesis_stubs only cover the strategies and decorators the existing property tests happen to use, so a test wanting hypothesis.stateful, or the timezones() / ip_addresses() strategies, fails to import when Hypothesis is not installed.

This adds those names. The stateful API has no equivalent of @example, so there is nothing for the stub to replay: a state machine's TestCase is skipped and run_state_machine_as_test raises SkipTest. The decorators are accepted so state machine classes can be defined at import time.

Real Hypothesis only exposes hypothesis.stateful once the submodule has been imported, so hypothesis_helper now imports it, making the attribute available in both modes.

The stubs had no tests of their own, so this also adds test_hypothesis_stubs, which checks the replay and skip behavior directly and runs the API-shape checks against the real package when it is importable (i.e. in the "Hypothesis tests on Ubuntu" job).

Groundwork for #107862; a stacked PR adding the first stateful/property users follows.

…thesis stubs

The stubs in test.support._hypothesis_stubs only cover the strategies
and decorators the existing property tests happen to use, so a test
that wants hypothesis.stateful, or the timezones() and ip_addresses()
strategies, fails to import when Hypothesis is not installed.

This adds those names. The stateful API has no equivalent of @example,
so there is nothing for the stub to replay: a state machine's TestCase
is skipped and run_state_machine_as_test raises SkipTest. The
decorators are accepted so that state machine classes can be defined
at import time.

Real Hypothesis only exposes hypothesis.stateful once the submodule has
been imported, so hypothesis_helper now imports it, making the
attribute available in both modes.
@pganssle
pganssle force-pushed the hypothesis-stubs-stateful branch from b88d3ad to aeb677f Compare October 19, 2026 21:30
@pganssle
pganssle marked this pull request as ready for review October 19, 2026 21:45
@pganssle
pganssle merged commit f5d989e into python:main Oct 20, 2026
56 of 57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants