"""Hypothesis under the repository's seed and budget convention. Importing this module registers two settings profiles and loads one (robot-docs/testing.md#seeds-and-budgets): - ``gate``, when ``ALBEDO_PROPERTY_SEED`` is unset: derandomized, so every run tries the same examples, with no example database. - ``discovery``, when it is ``random`` or an integer: fresh examples, and failures kept in an example database under the scratch root (``$ALBEDO_TEST_TMP/hypothesis``), never in the tree. An integer seed replays exactly that run. ``ALBEDO_PROPERTY_CASES`` sets ``max_examples``. A test that needs a smaller gate budget passes ``@settings(max_examples=cases(n))``, which the variable still overrides. Both profiles print the reproduction blob with the shrunk example, and a random run prints its ``@seed``, so the log alone reproduces a failure. Commit each shrunk counterexample as a named example test. """ import os from pathlib import Path from hypothesis import core, settings from hypothesis.database import DirectoryBasedExampleDatabase GATE_CASES = 100 DISCOVERY_CASES = 2000 ROOT = Path(os.environ.get("ALBEDO_TEST_TMP", "/tmp/albedo-tests")) def cases(gate: int) -> int: """A test's example budget: ``gate`` unless ``ALBEDO_PROPERTY_CASES`` is set.""" value = os.environ.get("ALBEDO_PROPERTY_CASES") return int(value) if value else gate def _load() -> str: seed = os.environ.get("ALBEDO_PROPERTY_SEED", "") common = settings(deadline=None, print_blob=True) settings.register_profile( "gate", derandomize=True, database=None, max_examples=cases(GATE_CASES), parent=common, ) settings.register_profile( "discovery", derandomize=False, database=DirectoryBasedExampleDatabase(ROOT / "hypothesis"), max_examples=cases(DISCOVERY_CASES), parent=common, ) if seed == "": profile = "gate" elif seed == "random": profile = "discovery" elif seed.isdigit(): profile = "discovery" # What `pytest --hypothesis-seed` sets. Hypothesis reads no seed from # the environment, and a forced seed skips the example database. setattr(core, "global_force_seed", int(seed)) else: raise ValueError( "ALBEDO_PROPERTY_SEED must be unset, 'random', or a non-negative integer" ) settings.load_profile(profile) return profile PROFILE = _load()