From 38af642d2f6079e586084ce4b84fc26919317f28 Mon Sep 17 00:00:00 2001 From: Vinetos Date: Tue, 10 Feb 2026 18:39:58 +0100 Subject: [PATCH 1/3] 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" From 0abace883ab9f26a99255bc756ee13f0ad996f69 Mon Sep 17 00:00:00 2001 From: Vinetos Date: Tue, 10 Feb 2026 19:18:30 +0100 Subject: [PATCH 2/3] python3Packages.python-openstackclient: use stestrCheckHook Signed-off-by: Vinetos --- .../python-openstackclient/default.nix | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/pkgs/development/python-modules/python-openstackclient/default.nix b/pkgs/development/python-modules/python-openstackclient/default.nix index d85fd1f1208d..bc21af90799d 100644 --- a/pkgs/development/python-modules/python-openstackclient/default.nix +++ b/pkgs/development/python-modules/python-openstackclient/default.nix @@ -19,7 +19,6 @@ python-mistralclient, python-neutronclient, python-octaviaclient, - python-openstackclient, python-watcherclient, python-zaqarclient, python-zunclient, @@ -28,8 +27,8 @@ setuptools, sphinxHook, sphinxcontrib-apidoc, - stestr, - testers, + stestrCheckHook, + versionCheckHook, }: buildPythonPackage (finalAttrs: { @@ -72,7 +71,7 @@ buildPythonPackage (finalAttrs: { nativeCheckInputs = [ ddt requests-mock - stestr + stestrCheckHook ]; disabledTestsRegex = [ @@ -112,12 +111,10 @@ buildPythonPackage (finalAttrs: { ]; }; - passthru = { - tests.version = testers.testVersion { - package = python-openstackclient; - command = "openstack --version"; - }; - }; + nativeInstallCheckInputs = [ + versionCheckHook + ]; + doInstallCheck = true; meta = { description = "OpenStack Command-line Client"; From 3e0e730e1362a5f14b736c92166ae3809b95bc52 Mon Sep 17 00:00:00 2001 From: Vinetos Date: Tue, 10 Feb 2026 22:30:13 +0100 Subject: [PATCH 3/3] python3Packages.python-heatclient: use stestrCheckHook Signed-off-by: Vinetos --- .../python-heatclient/default.nix | 86 ++++++++++++++----- 1 file changed, 64 insertions(+), 22 deletions(-) diff --git a/pkgs/development/python-modules/python-heatclient/default.nix b/pkgs/development/python-modules/python-heatclient/default.nix index f15df2138ba0..f0ae95acce82 100644 --- a/pkgs/development/python-modules/python-heatclient/default.nix +++ b/pkgs/development/python-modules/python-heatclient/default.nix @@ -2,7 +2,7 @@ lib, buildPythonPackage, cliff, - fetchPypi, + fetchFromGitHub, iso8601, keystoneauth1, openstackdocstheme, @@ -19,25 +19,30 @@ requests, setuptools, sphinxHook, - stestr, + stestrCheckHook, testscenarios, + versionCheckHook, }: -buildPythonPackage rec { +buildPythonPackage (finalAttrs: { pname = "python-heatclient"; version = "5.0.0"; pyproject = true; - src = fetchPypi { - pname = "python_heatclient"; - inherit version; - hash = "sha256-q3CtG+bRPo9gNHl6KJSutDU33EKUun/7C0pBe1ahpx4="; + src = fetchFromGitHub { + owner = "openstack"; + repo = "python-heatclient"; + tag = finalAttrs.version; + hash = "sha256-BpxUUQTBZLR89ks31q5BcBajIP2vcD3Oot1dsXLalX4="; }; + env.PBR_VERSION = finalAttrs.version; + build-system = [ openstackdocstheme python-openstackclient setuptools + pbr sphinxHook ]; @@ -51,7 +56,6 @@ buildPythonPackage rec { oslo-i18n oslo-serialization oslo-utils - pbr prettytable python-swiftclient pyyaml @@ -59,29 +63,67 @@ buildPythonPackage rec { ]; nativeCheckInputs = [ - stestr + stestrCheckHook testscenarios requests-mock ]; - checkPhase = '' - runHook preCheck + # These tests are failing on Python 3.14 because request.pathname2url fails to add // after the protocol's name. + # https://github.com/NixOS/nixpkgs/pull/488828#:~:text=discuss%2Epython%2Eorg%2Ft%2Fpathname2url%2Dchanges%2Din%2Dpython%2D3%2D14%2Dbreaking%2Dpip%2Dtests%2F97091 + disabledTests = [ + "heatclient.tests.unit.test_shell.ShellTestConfig.test_config_create" + "heatclient.tests.unit.test_shell.ShellTestStandaloneToken.test_stack_create_param_file" + "heatclient.tests.unit.test_shell.ShellTestStandaloneToken.test_stack_create_only_param_file" + "heatclient.tests.unit.test_shell.ShellTestToken.test_stack_create_only_param_file" + "heatclient.tests.unit.test_shell.ShellTestToken.test_stack_create_param_file" + "heatclient.tests.unit.test_shell.ShellTestUserPass.test_stack_create_param_file" + "heatclient.tests.unit.test_shell.ShellTestUserPass.test_stack_create_only_param_file" + "heatclient.tests.unit.test_shell.ShellTestUserPassKeystoneV3.test_stack_create_param_file" + "heatclient.tests.unit.test_shell.ShellTestUserPassKeystoneV3.test_stack_create_only_param_file" + "heatclient.tests.unit.test_template_utils.TestTemplateGetFileFunctions.test_hot_template" + "heatclient.tests.unit.test_template_utils.TestTemplateGetFileFunctions.test_hot_template_same_file" + "heatclient.tests.unit.test_template_utils.TestTemplateGetFileFunctions.test_hot_template_outputs" + "heatclient.tests.unit.test_template_utils.ShellEnvironmentTest.test_process_multiple_environments_empty_registry" + "heatclient.tests.unit.test_template_utils.ShellEnvironmentTest.test_process_multiple_environments_default_resources" + "heatclient.tests.unit.test_template_utils.ShellEnvironmentTest.test_ignore_env_keys" + "heatclient.tests.unit.test_template_utils.ShellEnvironmentTest.test_process_multiple_environments_and_files" + "heatclient.tests.unit.test_template_utils.ShellEnvironmentTest.test_process_environment_empty_file" + "heatclient.tests.unit.test_template_utils.ShellEnvironmentTest.test_process_environment_file" + "heatclient.tests.unit.test_template_utils.ShellEnvironmentTest.test_process_environment_relative_file" + "heatclient.tests.unit.test_template_utils.ShellEnvironmentTest.test_process_environment_relative_file_up" + "heatclient.tests.unit.test_template_utils.ShellEnvironmentTest.test_process_environment_relative_file_tracker" + "heatclient.tests.unit.test_template_utils.ShellEnvironmentTest.test_process_multiple_environments_and_files_tracker" + "heatclient.tests.unit.test_template_utils.TestTemplateTypeFunctions.test_hot_template" + "heatclient.tests.unit.test_template_utils.TestGetTemplateContents.test_get_template_contents_parse_error" + "heatclient.tests.unit.test_template_utils.TestGetTemplateContents.test_get_template_contents_file_empty" + "heatclient.tests.unit.test_template_utils.TestNestedIncludes.test_env_nested_includes" + "heatclient.tests.unit.test_template_utils.TestTemplateInFileFunctions.test_hot_template" + "heatclient.tests.unit.test_utils.TestURLFunctions.test_get_template_url" + "heatclient.tests.unit.test_utils.TestURLFunctions.test_normalise_file_path_to_url_absolute" + "heatclient.tests.unit.test_utils.TestURLFunctions.test_normalise_file_path_to_url_relative" + ]; - stestr run -e <(echo " - heatclient.tests.unit.test_common_http.HttpClientTest.test_get_system_ca_file - heatclient.tests.unit.test_deployment_utils.TempURLSignalTest.test_create_temp_url - ") + pythonImportsCheck = [ + "heatclient" + "heatclient.client" + "heatclient.common" + "heatclient.osc" + "heatclient.osc.v1" + "heatclient.tests" + "heatclient.tests.unit" + ]; - runHook postCheck - ''; - - pythonImportsCheck = [ "heatclient" ]; + nativeInstallCheckInputs = [ + versionCheckHook + ]; + doInstallCheck = true; meta = { - description = "Library for Heat built on the Heat orchestration API"; + description = "OpenStack Heat Client and bindings"; mainProgram = "heat"; - homepage = "https://github.com/openstack/python-heatclient"; + homepage = "https://docs.openstack.org/python-heatclient/latest/"; + downloadPage = "https://github.com/openstack/python-heatclient/releases/tag/${finalAttrs.src.tag}"; license = lib.licenses.asl20; teams = [ lib.teams.openstack ]; }; -} +})