From 38af642d2f6079e586084ce4b84fc26919317f28 Mon Sep 17 00:00:00 2001 From: Vinetos Date: Tue, 10 Feb 2026 18:39:58 +0100 Subject: [PATCH] stestrCheckHook: init This adds a useful hook to be used for projects that use stestr, it is primiative at the moment but covers most scenarios for using it. This PR also changes a Python module to start using it, once it lands, follow up PRs can update all of them to use it tree-wide. Signed-off-by: Vinetos --- doc/languages-frameworks/python.section.md | 1 + .../manual/release-notes/rl-2605.section.md | 2 + .../interpreters/python/hooks/default.nix | 11 ++++++ .../python/hooks/stestr-check-hook.sh | 39 +++++++++++++++++++ .../python-openstackclient/default.nix | 10 ++--- 5 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 pkgs/development/interpreters/python/hooks/stestr-check-hook.sh diff --git a/doc/languages-frameworks/python.section.md b/doc/languages-frameworks/python.section.md index bafa9fe12b91..9de335decf7e 100644 --- a/doc/languages-frameworks/python.section.md +++ b/doc/languages-frameworks/python.section.md @@ -550,6 +550,7 @@ are used in [`buildPythonPackage`](#buildpythonpackage-function). - `pythonRemoveBinBytecode` to remove bytecode from the `/bin` folder. - `setuptoolsBuildHook` to build a wheel using `setuptools`. - `sphinxHook` to build documentation and manpages using Sphinx. +- `stestrCheckHook` to run tests with `stestr`. - `venvShellHook` to source a Python 3 `venv` at the `venvDir` location. A `venv` is created if it does not yet exist. `postVenvCreation` can be used to to run commands only after venv is first created. diff --git a/nixos/doc/manual/release-notes/rl-2605.section.md b/nixos/doc/manual/release-notes/rl-2605.section.md index 1ec3860bcac2..4d438ceb2cb0 100644 --- a/nixos/doc/manual/release-notes/rl-2605.section.md +++ b/nixos/doc/manual/release-notes/rl-2605.section.md @@ -175,6 +175,8 @@ See . - Budgie has been updated to 10.10, please check the [upstream announcement](https://buddiesofbudgie.org/blog/budgie-10-10-released) for more details. +- `stestrCheckHook` was added: This test hook runs `stestr run`. You can disable tests with `disabledTests` and `disabledTestsRegex`. + - `services.frp` now supports multiple instances through `services.frp.instances` to make it possible to run multiple frp clients or servers at the same time. - `hyphen` now supports over 40 language variants through `hyphenDicts` and now allows to enable all supported languages through `hyphenDicts.all`. diff --git a/pkgs/development/interpreters/python/hooks/default.nix b/pkgs/development/interpreters/python/hooks/default.nix index 0bba05d7330e..079ec557d102 100644 --- a/pkgs/development/interpreters/python/hooks/default.nix +++ b/pkgs/development/interpreters/python/hooks/default.nix @@ -442,6 +442,17 @@ in } ./setuptools-build-hook.sh ) { }; + stestrCheckHook = callPackage ( + { makePythonHook }: + makePythonHook { + name = "stestr-check-hook"; + propagatedBuildInputs = [ stestr ]; + substitutions = { + inherit pythonCheckInterpreter; + }; + } ./stestr-check-hook.sh + ) { }; + unittestCheckHook = callPackage ( { makePythonHook }: makePythonHook { diff --git a/pkgs/development/interpreters/python/hooks/stestr-check-hook.sh b/pkgs/development/interpreters/python/hooks/stestr-check-hook.sh new file mode 100644 index 000000000000..f6db613b89d8 --- /dev/null +++ b/pkgs/development/interpreters/python/hooks/stestr-check-hook.sh @@ -0,0 +1,39 @@ +# Setup hook for stestr +# shellcheck shell=bash + +echo "Sourcing stestr-check-hook" + +function stestrCheckPhase() { + echo "Executing stestrCheckPhase" + runHook preCheck + + local -a patterns=() + + # Append regex pattern + read -ra patterns <<< "$disabledTestsRegex" + + # Sanitize disabledTests options + if [[ -n "${disabledTests[*]-}" ]] || [[ -n "${disabledTestsRegex[*]-}" ]]; then + # Prevent unintentional matching for specific tests + for test in ${disabledTests[@]-}; do + patterns+=("^${test}$") + done + fi + + # Compose arguments + local -a flagsArray=() + if [[ -n "${patterns[*]}" ]]; then + flagsArray+=(--exclude-regex "($(concatStringsSep "|" patterns))") + fi + + echoCmd 'stestr flags' "${flagsArray[@]}" + @pythonCheckInterpreter@ -m stestr run "${flagsArray[@]}" + + runHook postCheck + echo "Finished executing stestrCheckPhase" +} + +if [ -z "${dontUseStestrCheck-}" ] && [ -z "${installCheckPhase-}" ]; then + echo "Using stestrCheckPhase" + appendToVar preDistPhases stestrCheckPhase +fi diff --git a/pkgs/development/python-modules/python-openstackclient/default.nix b/pkgs/development/python-modules/python-openstackclient/default.nix index c629142ed547..d85fd1f1208d 100644 --- a/pkgs/development/python-modules/python-openstackclient/default.nix +++ b/pkgs/development/python-modules/python-openstackclient/default.nix @@ -75,13 +75,9 @@ buildPythonPackage (finalAttrs: { stestr ]; - # test_module failures under python 3.14: https://bugs.launchpad.net/python-openstackclient/+bug/2137223 - checkPhase = '' - runHook preCheck - stestr run -E \ - "openstackclient.tests.unit.common.test_module.TestModuleList.(test_module_list_no_options|test_module_list_all)" - runHook postCheck - ''; + disabledTestsRegex = [ + "openstackclient.tests.unit.common.test_module.TestModuleList*" + ]; pythonImportsCheck = [ "openstackclient"