Debian Codegraph @

hypothesis-python/tests/common/setup.py

raw
1 # This file is part of Hypothesis, which may be found at
2 # https://github.com/HypothesisWorks/hypothesis/
3 #
4 # Copyright the Hypothesis Authors.
5 # Individual contributors are listed in AUTHORS.rst and the git log.
6 #
7 # This Source Code Form is subject to the terms of the Mozilla Public License,
8 # v. 2.0. If a copy of the MPL was not distributed with this file, You can
9 # obtain one at https://mozilla.org/MPL/2.0/.
10
11 import os
12 from warnings import filterwarnings
13
14 from hypothesis import (
15 HealthCheck,
16 Phase,
17 Verbosity,
18 _settings as settings_module,
19 settings,
20 )
21 from hypothesis._settings import CI, default as default_settings, is_in_ci, not_set
22 from hypothesis.internal.conjecture.providers import AVAILABLE_PROVIDERS
23 from hypothesis.internal.coverage import IN_COVERAGE_TESTS
24
25
26 def run():
27 filterwarnings("error")
28 filterwarnings("ignore", category=ImportWarning)
29 filterwarnings("ignore", category=FutureWarning, module="pandas._version")
30
31 # See https://github.com/numpy/numpy/pull/432; still a thing as of 2022.
32 filterwarnings("ignore", message="numpy.dtype size changed")
33 filterwarnings("ignore", message="numpy.ufunc size changed")
34
35 # See https://github.com/HypothesisWorks/hypothesis/issues/1674
36 filterwarnings(
37 "ignore",
38 message=(
39 "The virtualenv distutils package at .+ appears to be in the "
40 "same location as the system distutils?"
41 ),
42 category=UserWarning,
43 )
44
45 # We do a smoke test here before we mess around with settings.
46 for setting_name in settings_module.all_settings:
47 # database value is dynamically calculated
48 if setting_name == "database":
49 continue
50
51 value = getattr(settings(), setting_name)
52 default_value = getattr(default_settings, setting_name)
53 assert value == default_value or (
54 is_in_ci() and value == getattr(CI, setting_name)
55 ), f"({value!r} == x.{setting_name}) != (s.{setting_name} == {default_value!r})"
56
57 settings.register_profile(
58 "default",
59 settings(
60 default_settings,
61 max_examples=20 if IN_COVERAGE_TESTS else not_set,
62 phases=list(Phase), # Dogfooding the explain phase
63 ),
64 )
65 settings.register_profile("speedy", max_examples=5)
66 settings.register_profile("debug", verbosity=Verbosity.debug)
67 settings.register_profile(
68 "threading",
69 # we would normally not disable the deadline here, but we disable the
70 # _consistently_increment_time fixture under threading tests (since
71 # monkeypatching is not thread safe), which leads to real deadline errors
72 # that are normally masked by that fixture.
73 deadline=None,
74 )
75
76 if "crosshair" in AVAILABLE_PROVIDERS:
77 settings.register_profile(
78 "crosshair",
79 # inherit from default profile, even on CI. See
80 # https://github.com/HypothesisWorks/hypothesis/pull/4536#issuecomment-3366741772
81 settings.get_profile("default"),
82 backend="crosshair",
83 max_examples=20,
84 deadline=None,
85 suppress_health_check=(HealthCheck.too_slow, HealthCheck.filter_too_much),
86 report_multiple_bugs=False,
87 )
88
89 for backend in set(AVAILABLE_PROVIDERS) - {"hypothesis", "crosshair"}:
90 settings.register_profile(backend, backend=backend)
91
92 settings.load_profile(os.getenv("HYPOTHESIS_PROFILE", "default"))