nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 buildPythonPackage,
4 isPyPy,
5 fetchFromGitHub,
6 setuptools,
7 attrs,
8 exceptiongroup,
9 pexpect,
10 doCheck ? true,
11 pytestCheckHook,
12 pytest-xdist,
13 sortedcontainers,
14 pythonAtLeast,
15 pythonOlder,
16 tzdata,
17}:
18
19buildPythonPackage rec {
20 pname = "hypothesis";
21 version = "6.136.9";
22 pyproject = true;
23
24 disabled = pythonOlder "3.9";
25
26 src = fetchFromGitHub {
27 owner = "HypothesisWorks";
28 repo = "hypothesis";
29 tag = "hypothesis-python-${version}";
30 hash = "sha256-Q1wxIJwAYKZ0x6c85CJSGgcdKw9a3xFw8YpJROElSNU=";
31 };
32
33 # I tried to package sphinx-selective-exclude, but it throws
34 # error about "module 'sphinx' has no attribute 'directives'".
35 #
36 # It probably has to do with monkey-patching internals of Sphinx.
37 # On bright side, this extension does not introduces new commands,
38 # only changes "::only" command, so we probably okay with stock
39 # implementation.
40 #
41 # I wonder how upstream of "hypothesis" builds documentation.
42 postPatch = ''
43 sed -i -e '/sphinx_selective_exclude.eager_only/ d' docs/conf.py
44 '';
45
46 postUnpack = "sourceRoot=$sourceRoot/hypothesis-python";
47
48 build-system = [ setuptools ];
49
50 dependencies = [
51 attrs
52 sortedcontainers
53 ]
54 ++ lib.optionals (pythonOlder "3.11") [ exceptiongroup ];
55
56 nativeCheckInputs = [
57 pexpect
58 pytest-xdist
59 pytestCheckHook
60 ]
61 ++ lib.optionals isPyPy [ tzdata ];
62
63 inherit doCheck;
64
65 # tox.ini changes how pytest runs and breaks it.
66 # Activate the CI profile (similar to setupHook below)
67 # by setting HYPOTHESIS_PROFILE [1].
68 #
69 # [1]: https://github.com/HypothesisWorks/hypothesis/blob/hypothesis-python-6.130.9/hypothesis-python/tests/common/setup.py#L78
70 preCheck = ''
71 rm tox.ini
72 export HYPOTHESIS_PROFILE=ci
73 '';
74
75 enabledTestPaths = [ "tests/cover" ];
76
77 # Hypothesis by default activates several "Health Checks", including one that fires if the builder is "too slow".
78 # This check is disabled [1] if Hypothesis detects a CI environment, i.e. either `CI` or `TF_BUILD` is defined [2].
79 # We set `CI=1` here using a setup hook to avoid spurious failures [3].
80 #
81 # Example error message for reference:
82 # hypothesis.errors.FailedHealthCheck: Data generation is extremely slow: Only produced 2 valid examples in 1.28 seconds (1 invalid ones and 0 exceeded maximum size). Try decreasing size of the data you're generating (with e.g. max_size or max_leaves parameters).
83 #
84 # [1]: https://github.com/HypothesisWorks/hypothesis/blob/hypothesis-python-6.130.9/hypothesis-python/src/hypothesis/_settings.py#L816-L828
85 # [2]: https://github.com/HypothesisWorks/hypothesis/blob/hypothesis-python-6.130.9/hypothesis-python/src/hypothesis/_settings.py#L756
86 # [3]: https://github.com/NixOS/nixpkgs/issues/393637
87 setupHook = ./setup-hook.sh;
88
89 disabledTests = [
90 # racy, fails to find a file sometimes
91 "test_recreate_charmap"
92 "test_uses_cached_charmap"
93 # fail when using CI profile
94 "test_given_does_not_pollute_state"
95 "test_find_does_not_pollute_state"
96 "test_does_print_on_reuse_from_database"
97 "test_prints_seed_only_on_healthcheck"
98 # calls script with the naked interpreter
99 "test_constants_from_running_file"
100 ]
101 ++ lib.optionals (pythonOlder "3.10") [
102 # not sure why these tests fail with only 3.9
103 # FileNotFoundError: [Errno 2] No such file or directory: 'git'
104 "test_observability"
105 "test_assume_has_status_reason"
106 "test_observability_captures_stateful_reprs"
107 ]
108 ++ lib.optionals (pythonAtLeast "3.12") [
109 # AssertionError: assert [b'def \... f(): pass'] == [b'def\\', b' f(): pass']
110 # https://github.com/HypothesisWorks/hypothesis/issues/4355
111 "test_clean_source"
112 ]
113 ++ lib.optionals (pythonAtLeast "3.14") [
114 "test_attrs_inference_builds"
115 "test_bound_missing_dot_access_forward_ref"
116 "test_bound_missing_forward_ref"
117 "test_bound_type_checking_only_forward_ref_wrong_type"
118 "test_bound_type_cheking_only_forward_ref"
119 "test_builds_suggests_from_type"
120 "test_bytestring_not_treated_as_generic_sequence"
121 "test_evil_prng_registration_nonsense"
122 "test_issue_4194_regression"
123 "test_passing_referenced_instance_within_function_scope_warns"
124 "test_registering_a_Random_is_idempotent"
125 "test_register_random_within_nested_function_scope"
126 "test_resolve_fwd_refs"
127 "test_resolves_forwardrefs_to_builtin_types"
128 "test_resolving_standard_collection_as_generic"
129 "test_resolving_standard_container_as_generic"
130 "test_resolving_standard_contextmanager_as_generic"
131 "test_resolving_standard_iterable_as_generic"
132 "test_resolving_standard_reversible_as_generic"
133 "test_resolving_standard_sequence_as_generic"
134 "test_specialised_collection_types"
135 ];
136
137 pythonImportsCheck = [ "hypothesis" ];
138
139 meta = {
140 description = "Library for property based testing";
141 mainProgram = "hypothesis";
142 homepage = "https://github.com/HypothesisWorks/hypothesis";
143 changelog = "https://hypothesis.readthedocs.io/en/latest/changes.html#v${
144 lib.replaceStrings [ "." ] [ "-" ] version
145 }";
146 license = lib.licenses.mpl20;
147 maintainers = [
148 lib.maintainers.fliegendewurst
149 ];
150 };
151}