Hypothesis has minimal dependencies (just attrs), to maximise compatibility and make installing Hypothesis as easy as possible.
Our integrations with specific packages are therefore provided by
modules that need their individual dependencies installed in order to work.
You can install these dependencies using the setuptools extra feature as e.g.
pip install hypothesis[django]. This will check installation of compatible versions.
You can also just install hypothesis into a project using them, ignore the version constraints, and hope for the best.
In general “Which version is Hypothesis compatible with?” is a hard question to answer and even harder to regularly test. Hypothesis is always tested against the latest compatible version and each package will note the expected compatibility range. If you run into a bug with any of these please specify the dependency version.
This module provides tools for working with the dpcontracts library, because combining contracts and property-based testing works really well.
dpcontracts >= 0.4.
contract_functo reject calls which violate preconditions, and retry them with different arguments.
This is a convenience function for testing internal code that uses dpcontracts, to automatically filter out arguments that would be rejected by the public interface before triggering a contract error.
This can be used as
builds(fulfill(func), ...)or in the body of the test e.g.
This extra can be used to generate strings matching any context-free grammar, using the Lark parser library.
It currently only supports Lark’s native EBNF syntax, but we plan to extend this to support other common syntaxes such as ANTLR and RFC 5234 ABNF. Lark already supports loading grammars from nearley.js, so you may not have to write your own at all.
Note that as Lark is at version 0.x, this module may break API compatibility in minor releases if supporting the latest version of Lark would otherwise be infeasible. We may also be quite aggressive in bumping the minimum version of Lark, unless someone volunteers to either fund or do the maintainence.
from_lark(grammar, start=None, explicit=None)¶
A strategy for strings accepted by the given context-free grammar.
grammarmust be a
Larkobject, which wraps an EBNF specification. The Lark EBNF grammar reference can be found here.
from_larkwill automatically generate strings matching the nonterminal
startsymbol in the grammar, which was supplied as an argument to the Lark class. To generate strings matching a different symbol, including terminals, you can override this by passing the
from_lark. Note that Lark may remove unreachable productions when the grammar is compiled, so you should probably pass the same value for
from_larkdoes not support grammars that need custom lexing. Any lexers will be ignored, and any undefined terminals from the use of
%declarewill result in generation errors. To define strategies for such terminals, pass a dictionary mapping their name to a corresponding strategy as the
The hypothesmith project includes a strategy for Python source, based on a grammar and careful post-processing.
This module provides pytz timezones.
This module provides
Any timezone in dateutil.
This strategy minimises to UTC, or the timezone with the smallest offset from UTC as of 2000-01-01, and is designed for use with
Note that the timezones generated by the strategy may vary depending on the configuration of your machine. See the dateutil documentation for more information.