pytestCheckHook: fix disabledTestPaths glob matching assertion (#386491)

This commit is contained in:
Martin Weinelt
2025-03-07 08:25:48 +01:00
committed by GitHub
2 changed files with 49 additions and 3 deletions

View File

@@ -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
) { };

View File

@@ -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 <<EOF
@pythonCheckInterpreter@ - "$path" <<EOF
import glob
import sys
path_glob=sys.argv[1]
@@ -27,7 +27,6 @@ if not len(path_glob):
if next(glob.iglob(path_glob), None) is None:
sys.exit('Disabled tests path glob "{}" does not match any paths. Aborting'.format(path_glob))
EOF
) "$path"
flagsArray+=("--ignore-glob=$path")
done