depot/third_party/nixpkgs/pkgs/development/interpreters/python/hooks/pytest-check-hook.sh
Default email 8ac5e011d6 Project import generated by Copybara.
GitOrigin-RevId: 2c3273caa153ee8eb5786bc8141b85b859e7efd7
2020-04-24 19:36:52 -04:00

49 lines
1.2 KiB
Bash

# Setup hook for pytest
echo "Sourcing pytest-check-hook"
declare -ar disabledTests
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
args+=" ${pytestFlagsArray[@]}"
eval "@pythonCheckInterpreter@ $args"
runHook postCheck
echo "Finished executing pytestCheckPhase"
}
if [ -z "${dontUsePytestCheck-}" ] && [ -z "${installCheckPhase-}" ]; then
echo "Using pytestCheckPhase"
preDistPhases+=" pytestCheckPhase"
fi