Skip to content

Commit 014dd30

Browse files
authored
gh-86275: improve Hypothesis configuration for CI and local runs (#104468)
1 parent be0c106 commit 014dd30

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

.github/workflows/build.yml

+13
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,14 @@ jobs:
368368
echo "HYPOVENV=${VENV_LOC}" >> $GITHUB_ENV
369369
echo "VENV_PYTHON=${VENV_PYTHON}" >> $GITHUB_ENV
370370
./python -m venv $VENV_LOC && $VENV_PYTHON -m pip install -U hypothesis
371+
- name: 'Restore Hypothesis database'
372+
id: cache-hypothesis-database
373+
uses: actions/cache@v3
374+
with:
375+
path: ./hypothesis
376+
key: hypothesis-database-${{ github.head_ref || github.run_id }}
377+
restore-keys: |
378+
- hypothesis-database-
371379
- name: "Run tests"
372380
working-directory: ${{ env.CPYTHON_BUILDDIR }}
373381
run: |
@@ -388,6 +396,11 @@ jobs:
388396
-x test_subprocess \
389397
-x test_signal \
390398
-x test_sysconfig
399+
- uses: actions/upload-artifact@v3
400+
if: always()
401+
with:
402+
name: hypothesis-example-db
403+
path: .hypothesis/examples/
391404

392405

393406
build_asan:

Lib/test/support/hypothesis_helper.py

+31
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
1+
import os
2+
13
try:
24
import hypothesis
35
except ImportError:
46
from . import _hypothesis_stubs as hypothesis
7+
else:
8+
# When using the real Hypothesis, we'll configure it to ignore occasional
9+
# slow tests (avoiding flakiness from random VM slowness in CI).
10+
hypothesis.settings.register_profile(
11+
"slow-is-ok",
12+
deadline=None,
13+
suppress_health_check=[hypothesis.HealthCheck.too_slow],
14+
)
15+
hypothesis.settings.load_profile("slow-is-ok")
16+
17+
# For local development, we'll write to the default on-local-disk database
18+
# of failing examples, and also use a pull-through cache to automatically
19+
# replay any failing examples discovered in CI. For details on how this
20+
# works, see https://hypothesis.readthedocs.io/en/latest/database.html
21+
if "CI" not in os.environ:
22+
from hypothesis.database import (
23+
GitHubArtifactDatabase,
24+
MultiplexedDatabase,
25+
ReadOnlyDatabase,
26+
)
27+
28+
hypothesis.settings.register_profile(
29+
"cpython-local-dev",
30+
database=MultiplexedDatabase(
31+
hypothesis.settings.default.database,
32+
ReadOnlyDatabase(GitHubArtifactDatabase("python", "cpython")),
33+
),
34+
)
35+
hypothesis.settings.load_profile("cpython-local-dev")

0 commit comments

Comments
 (0)