| 1 |
import os |
| 2 |
|
| 3 |
try: |
| 4 |
import hypothesis |
| 5 |
except ImportError: |
| 6 |
from . import _hypothesis_stubs as hypothesis |
| 7 |
else: |
| 8 |
# Regrtest changes to use a tempdir as the working directory, so we have |
| 9 |
# to tell Hypothesis to use the original in order to persist the database. |
| 10 |
from test.support import has_socket_support |
| 11 |
from test.support.os_helper import SAVEDCWD |
| 12 |
from hypothesis.configuration import set_hypothesis_home_dir |
| 13 |
|
| 14 |
set_hypothesis_home_dir(os.path.join(SAVEDCWD, ".hypothesis")) |
| 15 |
|
| 16 |
# When using the real Hypothesis, we'll configure it to ignore occasional |
| 17 |
# slow tests (avoiding flakiness from random VM slowness in CI). |
| 18 |
hypothesis.settings.register_profile( |
| 19 |
"slow-is-ok", |
| 20 |
deadline=None, |
| 21 |
suppress_health_check=[ |
| 22 |
hypothesis.HealthCheck.too_slow, |
| 23 |
hypothesis.HealthCheck.differing_executors, |
| 24 |
], |
| 25 |
) |
| 26 |
hypothesis.settings.load_profile("slow-is-ok") |
| 27 |
|
| 28 |
# For local development, we'll write to the default on-local-disk database |
| 29 |
# of failing examples, and also use a pull-through cache to automatically |
| 30 |
# replay any failing examples discovered in CI. For details on how this |
| 31 |
# works, see https://hypothesis.readthedocs.io/en/latest/database.html |
| 32 |
# We only do that if a GITHUB_TOKEN env var is provided, see: |
| 33 |
# https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens |
| 34 |
# And Python is built with socket support: |
| 35 |
if ( |
| 36 |
has_socket_support |
| 37 |
and "CI" not in os.environ |
| 38 |
and "GITHUB_TOKEN" in os.environ |
| 39 |
): |
| 40 |
from hypothesis.database import ( |
| 41 |
GitHubArtifactDatabase, |
| 42 |
MultiplexedDatabase, |
| 43 |
ReadOnlyDatabase, |
| 44 |
) |
| 45 |
|
| 46 |
hypothesis.settings.register_profile( |
| 47 |
"cpython-local-dev", |
| 48 |
database=MultiplexedDatabase( |
| 49 |
hypothesis.settings.default.database, |
| 50 |
ReadOnlyDatabase(GitHubArtifactDatabase("python", "cpython")), |
| 51 |
), |
| 52 |
) |
| 53 |
hypothesis.settings.load_profile("cpython-local-dev") |