2019-07-17 20:36:47 +02:00
|
|
|
# Setup hook for pytest
|
|
|
|
echo "Sourcing pytest-check-hook"
|
|
|
|
|
|
|
|
declare -ar disabledTests
|
2021-02-19 15:58:39 +01:00
|
|
|
declare -a disabledTestPaths
|
2019-07-17 20:36:47 +02:00
|
|
|
|
|
|
|
function _concatSep {
|
|
|
|
local result
|
|
|
|
local sep="$1"
|
|
|
|
local -n arr=$2
|
|
|
|
for index in ${!arr[*]}; do
|
|
|
|
if [ $index -eq 0 ]; then
|
|
|
|
result="${arr[index]}"
|
|
|
|
else
|
|
|
|
result+=" $sep ${arr[index]}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "$result"
|
|
|
|
}
|
|
|
|
|
|
|
|
function _pytestComputeDisabledTestsString () {
|
|
|
|
declare -a tests
|
|
|
|
local tests=($1)
|
|
|
|
local prefix="not "
|
|
|
|
prefixed=( "${tests[@]/#/$prefix}" )
|
|
|
|
result=$(_concatSep "and" prefixed)
|
|
|
|
echo "$result"
|
|
|
|
}
|
|
|
|
|
|
|
|
function pytestCheckPhase() {
|
|
|
|
echo "Executing pytestCheckPhase"
|
|
|
|
runHook preCheck
|
|
|
|
|
|
|
|
# Compose arguments
|
|
|
|
args=" -m pytest"
|
|
|
|
if [ -n "$disabledTests" ]; then
|
|
|
|
disabledTestsString=$(_pytestComputeDisabledTestsString "${disabledTests[@]}")
|
|
|
|
args+=" -k \""$disabledTestsString"\""
|
|
|
|
fi
|
2021-02-19 15:58:39 +01:00
|
|
|
|
|
|
|
if [ -n "${disabledTestPaths-}" ]; then
|
|
|
|
eval "disabledTestPaths=($disabledTestPaths)"
|
|
|
|
fi
|
|
|
|
|
2021-02-14 23:54:55 +01:00
|
|
|
for path in ${disabledTestPaths[@]}; do
|
|
|
|
if [ ! -e "$path" ]; then
|
|
|
|
echo "Disabled tests path \"$path\" does not exist. Aborting"
|
2021-01-06 00:32:27 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
2021-02-14 23:54:55 +01:00
|
|
|
args+=" --ignore=\"$path\""
|
2021-01-06 00:32:27 +01:00
|
|
|
done
|
2019-07-17 20:36:47 +02:00
|
|
|
args+=" ${pytestFlagsArray[@]}"
|
|
|
|
eval "@pythonCheckInterpreter@ $args"
|
|
|
|
|
|
|
|
runHook postCheck
|
|
|
|
echo "Finished executing pytestCheckPhase"
|
|
|
|
}
|
|
|
|
|
2019-10-31 18:59:18 +01:00
|
|
|
if [ -z "${dontUsePytestCheck-}" ] && [ -z "${installCheckPhase-}" ]; then
|
2019-07-17 20:36:47 +02:00
|
|
|
echo "Using pytestCheckPhase"
|
|
|
|
preDistPhases+=" pytestCheckPhase"
|
2020-03-30 10:59:01 +02:00
|
|
|
|
|
|
|
# It's almost always the case that setuptoolsCheckPhase should not be ran
|
|
|
|
# when the pytestCheckHook is being ran
|
|
|
|
if [ -z "${useSetuptoolsCheck-}" ]; then
|
|
|
|
dontUseSetuptoolsCheck=1
|
|
|
|
|
|
|
|
# Remove command if already injected into preDistPhases
|
|
|
|
if [[ "$preDistPhases" =~ "setuptoolsCheckPhase" ]]; then
|
|
|
|
echo "Removing setuptoolsCheckPhase"
|
|
|
|
preDistPhases=${preDistPhases/setuptoolsCheckPhase/}
|
|
|
|
fi
|
|
|
|
fi
|
2019-07-17 20:36:47 +02:00
|
|
|
fi
|