From 55cb5e1e0641a1d6e2e10e78eda83e7ed86e8f22 Mon Sep 17 00:00:00 2001 From: FliegendeWurst Date: Sat, 12 Apr 2025 11:30:06 +0200 Subject: [PATCH] python3Packages.hypothesis: fix downstream flaky test failures --- .../python-modules/hypothesis/default.nix | 36 +++++++++++++++---- .../python-modules/hypothesis/setup-hook.sh | 5 +++ 2 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 pkgs/development/python-modules/hypothesis/setup-hook.sh diff --git a/pkgs/development/python-modules/hypothesis/default.nix b/pkgs/development/python-modules/hypothesis/default.nix index 1bf8fa98be5e..6c97e9b54b54 100644 --- a/pkgs/development/python-modules/hypothesis/default.nix +++ b/pkgs/development/python-modules/hypothesis/default.nix @@ -27,7 +27,7 @@ buildPythonPackage rec { version = "6.130.12"; pyproject = true; - disabled = pythonOlder "3.7"; + disabled = pythonOlder "3.9"; src = fetchFromGitHub { owner = "HypothesisWorks"; @@ -66,20 +66,40 @@ buildPythonPackage rec { inherit doCheck; - # This file changes how pytest runs and breaks it + # tox.ini changes how pytest runs and breaks it. + # Activate the CI profile (similar to setupHook below) + # by setting HYPOTHESIS_PROFILE [1]. + # + # [1]: https://github.com/HypothesisWorks/hypothesis/blob/hypothesis-python-6.130.9/hypothesis-python/tests/common/setup.py#L78 preCheck = '' rm tox.ini + export HYPOTHESIS_PROFILE=ci ''; pytestFlagsArray = [ "tests/cover" ]; + # Hypothesis by default activates several "Health Checks", including one that fires if the builder is "too slow". + # This check is disabled [1] if Hypothesis detects a CI environment, i.e. either `CI` or `TF_BUILD` is defined [2]. + # We set `CI=1` here using a setup hook to avoid spurious failures [3]. + # + # Example error message for reference: + # hypothesis.errors.FailedHealthCheck: Data generation is extremely slow: Only produced 2 valid examples in 1.28 seconds (1 invalid ones and 0 exceeded maximum size). Try decreasing size of the data you're generating (with e.g. max_size or max_leaves parameters). + # + # [1]: https://github.com/HypothesisWorks/hypothesis/blob/hypothesis-python-6.130.9/hypothesis-python/src/hypothesis/_settings.py#L816-L828 + # [2]: https://github.com/HypothesisWorks/hypothesis/blob/hypothesis-python-6.130.9/hypothesis-python/src/hypothesis/_settings.py#L756 + # [3]: https://github.com/NixOS/nixpkgs/issues/393637 + setupHook = ./setup-hook.sh; + disabledTests = [ # racy, fails to find a file sometimes "test_recreate_charmap" "test_uses_cached_charmap" - # fails if builder is too slow - "test_can_run_with_no_db" + # fail when using CI profile + "test_given_does_not_pollute_state" + "test_find_does_not_pollute_state" + "test_does_print_on_reuse_from_database" + "test_prints_seed_only_on_healthcheck" # calls script with the naked interpreter "test_constants_from_running_file" ] @@ -122,14 +142,16 @@ buildPythonPackage rec { }; }; - meta = with lib; { + meta = { description = "Library for property based testing"; mainProgram = "hypothesis"; homepage = "https://github.com/HypothesisWorks/hypothesis"; changelog = "https://hypothesis.readthedocs.io/en/latest/changes.html#v${ lib.replaceStrings [ "." ] [ "-" ] version }"; - license = licenses.mpl20; - maintainers = [ ]; + license = lib.licenses.mpl20; + maintainers = [ + lib.maintainers.fliegendewurst + ]; }; } diff --git a/pkgs/development/python-modules/hypothesis/setup-hook.sh b/pkgs/development/python-modules/hypothesis/setup-hook.sh new file mode 100644 index 000000000000..90986ac8bff9 --- /dev/null +++ b/pkgs/development/python-modules/hypothesis/setup-hook.sh @@ -0,0 +1,5 @@ +hypothesisActivateProfileForCI() { + export CI=1 +} + +postHooks+=(hypothesisActivateProfileForCI)