mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-14 14:10:33 +03:00
pytestCheckHook: support __structuredAttrs
Add flag pytestFlags as the new, conforming interface replacing pytestFlagsArray. Stop Bash-expanding disabledTests and disabledTestPaths. Handle disabledTestPaths with `pytest --ignore-glob <path>` to keep globbing support. Check if each path glob matches at least one path using the `glob` module from the Python standard library. Also make buildPythonPackage and buildPythonApplication stop escaping the elements of disabledTests and disabledTestPaths.
This commit is contained in:
parent
e8f3fe8c6e
commit
26f09762a8
3 changed files with 40 additions and 24 deletions
|
@ -1,33 +1,41 @@
|
|||
# Setup hook for pytest
|
||||
echo "Sourcing pytest-check-hook"
|
||||
|
||||
declare -ar disabledTests
|
||||
declare -a disabledTestPaths
|
||||
echo "Sourcing pytest-check-hook"
|
||||
|
||||
function pytestCheckPhase() {
|
||||
echo "Executing pytestCheckPhase"
|
||||
runHook preCheck
|
||||
|
||||
# Compose arguments
|
||||
args=" -m pytest"
|
||||
if [ -n "$disabledTests" ]; then
|
||||
local -a flagsArray=(-m pytest)
|
||||
if [ -n "${disabledTests[*]-}" ]; then
|
||||
disabledTestsString="not $(concatStringsSep " and not " disabledTests)"
|
||||
args+=" -k \""$disabledTestsString"\""
|
||||
flagsArray+=(-k "$disabledTestsString")
|
||||
fi
|
||||
|
||||
if [ -n "${disabledTestPaths-}" ]; then
|
||||
eval "disabledTestPaths=($disabledTestPaths)"
|
||||
fi
|
||||
|
||||
for path in ${disabledTestPaths[@]}; do
|
||||
if [ ! -e "$path" ]; then
|
||||
echo "Disabled tests path \"$path\" does not exist. Aborting"
|
||||
exit 1
|
||||
fi
|
||||
args+=" --ignore=\"$path\""
|
||||
local -a _pathsArray=()
|
||||
concatTo _pathsArray disabledTestPaths
|
||||
for path in "${_pathsArray[@]}"; do
|
||||
# Check if every path glob matches at least one path
|
||||
@pythonCheckInterpreter@ <(cat <<EOF
|
||||
import glob
|
||||
import sys
|
||||
path_glob=sys.argv[1]
|
||||
if not len(path_glob):
|
||||
sys.exit('Got an empty disabled tests path glob. Aborting')
|
||||
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
|
||||
args+=" ${pytestFlagsArray[@]}"
|
||||
eval "@pythonCheckInterpreter@ $args"
|
||||
|
||||
# Compatibility layer to the obsolete pytestFlagsArray
|
||||
eval "flagsArray+=(${pytestFlagsArray[*]-})"
|
||||
|
||||
concatTo flagsArray pytestFlags
|
||||
echoCmd 'pytest flags' "${flagsArray[@]}"
|
||||
@pythonCheckInterpreter@ "${flagsArray[@]}"
|
||||
|
||||
runHook postCheck
|
||||
echo "Finished executing pytestCheckPhase"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue