From ed5bc467939304d9ffa7dd5e4f302277bb56a2e2 Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Tue, 27 Oct 2026 21:05:25 +0530 Subject: [PATCH] Tests: Add Hypothesis, with dev, ci and thorough profiles hypothesis joins the test extra. conftest.py registers three profiles, chosen with HYPOTHESIS_PROFILE: - dev (the default): 100 examples. - ci: 100 examples, derandomized, so a CI failure always reproduces. - thorough: 3000 examples, for bug hunting. None of them has a deadline: an example compiles a program twice. CI runs the suite with the ci profile. The example database (.hypothesis/) is ignored. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test.yml | 3 +++ .gitignore | 1 + pyproject.toml | 1 + tests/conftest.py | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+) 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