python3Packages.pytestCheckHook: support enabledTests

This commit is contained in:
Yueh-Shun Li
2025-03-23 23:51:16 +08:00
parent f51e1c6766
commit f7aeb5a9b7
3 changed files with 47 additions and 7 deletions
@@ -212,6 +212,29 @@ in
] ++ previousPythonAttrs.disabledTestPaths or [ ];
})
);
enabledTests = objprint.overridePythonAttrs (previousPythonAttrs: {
pname = "test-pytestCheckHook-enabledTests-${previousPythonAttrs.pname}";
enabledTests = [
"TestBasic"
] ++ previousPythonAttrs.disabledTests or [ ];
});
enabledTests-expression = objprint.overridePythonAttrs (previousPythonAttrs: {
__structuredAttrs = true;
pname = "test-pytestCheckHook-enabledTests-expression-${previousPythonAttrs.pname}";
enabledTests = [
"TestBasic and test_print"
"test_str"
] ++ previousPythonAttrs.disabledTests or [ ];
});
enabledTests-disabledTests = objprint.overridePythonAttrs (previousPythonAttrs: {
pname = "test-pytestCheckHook-enabledTests-disabledTests-${previousPythonAttrs.pname}";
enabledTests = [
"TestBasic"
] ++ previousPythonAttrs.disabledTests or [ ];
disabledTests = [
"test_print"
] ++ previousPythonAttrs.disabledTests or [ ];
});
enabledTestPaths = objprint.overridePythonAttrs (previousPythonAttrs: {
pname = "test-pytestCheckHook-enabledTestPaths-${previousPythonAttrs.pname}";
enabledTestPaths = [
@@ -3,6 +3,23 @@
echo "Sourcing pytest-check-hook"
function _pytestIncludeExcludeExpr() {
local includeListName="$1"
local -n includeListRef="$includeListName"
local excludeListName="$2"
local -n excludeListRef="$excludeListName"
local includeString excludeString
if [[ -n "${includeListRef[*]-}" ]]; then
# ((element1) or (element2))
includeString="(($(concatStringsSep ") or (" "$includeListName")))"
fi
if [[ -n "${excludeListRef[*]-}" ]]; then
# and not (element1) and not (element2)
excludeString="${includeString:+ and }not ($(concatStringsSep ") and not (" "$excludeListName"))"
fi
echo "$includeString$excludeString"
}
function pytestCheckPhase() {
echo "Executing pytestCheckPhase"
runHook preCheck
@@ -56,10 +73,8 @@ EOF
fi
done
if [ -n "${disabledTests[*]-}" ]; then
# not (keyword1) and not (keyword2)
disabledTestsString="not ($(concatStringsSep ") and not (" disabledTests))"
flagsArray+=(-k "$disabledTestsString")
if [[ -n "${enabledTests[*]-}" ]] || [[ -n "${disabledTests[*]-}" ]]; then
flagsArray+=(-k "$(_pytestIncludeExcludeExpr enabledTests disabledTests)")
fi
# Compatibility layer to the obsolete pytestFlagsArray
@@ -109,6 +109,7 @@ let
"disabledTestPaths"
"disabledTests"
"enabledTestPaths"
"enabledTests"
"pytestFlags"
"pytestFlagsArray"
"unittestFlags"
@@ -451,13 +452,14 @@ let
lib.mapAttrs
(
name: value:
lib.throwIf (attrs.${name} == [ ])
"${lib.getName finalAttrs}: ${name} must be unspecified, null or a non-empty list."
attrs.${name}
lib.throwIf (
attrs.${name} == [ ]
) "${lib.getName finalAttrs}: ${name} must be unspecified, null or a non-empty list." attrs.${name}
)
(
getOptionalAttrs [
"enabledTestPaths"
"enabledTests"
] attrs
)
)