From 2e512e7cf7d95f8a0249c8e4fc3ede0720a719e0 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 3 Mar 2025 00:57:23 +0800 Subject: [PATCH 1/2] python3Packages.pytestCheckHook: fix disabledTestPaths glob matching assertion Errors in Bash's process substitution doesn't get propagated outside. Replace the process substitution with Python's `-` as /dev/stdin and Bash's heredoc stdin redirection. --- .../development/interpreters/python/hooks/pytest-check-hook.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkgs/development/interpreters/python/hooks/pytest-check-hook.sh b/pkgs/development/interpreters/python/hooks/pytest-check-hook.sh index 855c770e31b1..ff95f73ba20c 100644 --- a/pkgs/development/interpreters/python/hooks/pytest-check-hook.sh +++ b/pkgs/development/interpreters/python/hooks/pytest-check-hook.sh @@ -18,7 +18,7 @@ function pytestCheckPhase() { concatTo _pathsArray disabledTestPaths for path in "${_pathsArray[@]}"; do # Check if every path glob matches at least one path - @pythonCheckInterpreter@ <(cat < Date: Fri, 7 Mar 2025 03:01:26 +0800 Subject: [PATCH 2/2] python3Packages.pytestCheckHook: add tests --- .../interpreters/python/hooks/default.nix | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/pkgs/development/interpreters/python/hooks/default.nix b/pkgs/development/interpreters/python/hooks/default.nix index 38afdb3026b9..d8b8f661ee2a 100644 --- a/pkgs/development/interpreters/python/hooks/default.nix +++ b/pkgs/development/interpreters/python/hooks/default.nix @@ -146,13 +146,60 @@ in }; pytestCheckHook = callPackage ( - { makePythonHook, pytest }: + { + makePythonHook, + pytest, + # For package tests + testers, + objprint, + }: makePythonHook { name = "pytest-check-hook"; propagatedBuildInputs = [ pytest ]; substitutions = { inherit pythonCheckInterpreter; }; + passthru = { + tests = { + basic = objprint.overridePythonAttrs (previousPythonAttrs: { + pname = "test-pytestCheckHook-basic-${previousPythonAttrs.pname}"; + }); + disabledTests = objprint.overridePythonAttrs (previousPythonAttrs: { + pname = "test-pytestCheckHook-disabledTests-${previousPythonAttrs.pname}"; + disabledTests = [ + "test_print" + ] ++ previousPythonAttrs.disabledTests or [ ]; + }); + disabledTestPaths = objprint.overridePythonAttrs (previousPythonAttrs: { + pname = "test-pytestCheckHook-disabledTestPaths-${previousPythonAttrs.pname}"; + disabledTestPaths = [ + "tests/test_basic.py" + ] ++ previousPythonAttrs.disabledTestPaths or [ ]; + }); + disabledTestPaths-nonexistent = testers.testBuildFailure ( + objprint.overridePythonAttrs (previousPythonAttrs: { + pname = "test-pytestCheckHook-disabledTestPaths-nonexistent-${previousPythonAttrs.pname}"; + disabledTestPaths = [ + "tests/test_foo.py" + ] ++ previousPythonAttrs.disabledTestPaths or [ ]; + }) + ); + disabledTestPaths-glob = objprint.overridePythonAttrs (previousPythonAttrs: { + pname = "test-pytestCheckHook-disabledTestPaths-glob-${previousPythonAttrs.pname}"; + disabledTestPaths = [ + "tests/test_obj*.py" + ] ++ previousPythonAttrs.disabledTestPaths or [ ]; + }); + disabledTestPaths-glob-nonexistent = testers.testBuildFailure ( + objprint.overridePythonAttrs (previousPythonAttrs: { + pname = "test-pytestCheckHook-disabledTestPaths-glob-nonexistent-${previousPythonAttrs.pname}"; + disabledTestPaths = [ + "tests/test_foo*.py" + ] ++ previousPythonAttrs.disabledTestPaths or [ ]; + }) + ); + }; + }; } ./pytest-check-hook.sh ) { };