diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f510c69..3ab5ec3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -72,6 +72,9 @@ jobs: run: uv pip install --system -e ".[test]" - name: Run test suite + env: + # tests/property: derandomized, so a failure always reproduces + HYPOTHESIS_PROFILE: ci run: make test - name: Check whether sudo is usable diff --git a/.gitignore b/.gitignore index bb41570..d232ae6 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ vmlinux.h # Documentation build artifacts docs/_build/ docs/_templates/ +.hypothesis/ diff --git a/pyproject.toml b/pyproject.toml index 40c07e7..e18f4fd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,6 +42,7 @@ docs = [ test = [ "pytest>=8.0", "pytest-cov>=5.0", + "hypothesis>=6.100", "ctypeslib2", # Pinned rather than left to ctypeslib2's own (unpinned) dependency: pip # installs the latest release by default, and its libclang API surface diff --git a/tests/conftest.py b/tests/conftest.py index f70dee2..0a6665d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -116,3 +116,22 @@ def pytest_collection_modifyitems(items): def set_log_level(caplog): with caplog.at_level(logging.ERROR, logger="pythonbpf"): yield + + +# ── Hypothesis profiles (tests/property) ──────────────────────────────────── +# dev (default) for local runs, ci for GitHub Actions (derandomized, so a PR +# never fails on an example nobody can reproduce), thorough for bug hunting: +# HYPOTHESIS_PROFILE=thorough pytest tests/property + +try: + import os + + from hypothesis import HealthCheck, settings + + _common = dict(deadline=None, suppress_health_check=[HealthCheck.too_slow]) + settings.register_profile("dev", max_examples=100, **_common) + settings.register_profile("ci", max_examples=100, derandomize=True, **_common) + settings.register_profile("thorough", max_examples=3000, **_common) + settings.load_profile(os.environ.get("HYPOTHESIS_PROFILE", "dev")) +except ImportError: + pass