1# Setup hook for pytest
2echo "Sourcing pytest-check-hook"
3
4declare -ar disabledTests
5
6function _concatSep {
7 local result
8 local sep="$1"
9 local -n arr=$2
10 for index in ${!arr[*]}; do
11 if [ $index -eq 0 ]; then
12 result="${arr[index]}"
13 else
14 result+=" $sep ${arr[index]}"
15 fi
16 done
17 echo "$result"
18}
19
20function _pytestComputeDisabledTestsString () {
21 declare -a tests
22 local tests=($1)
23 local prefix="not "
24 prefixed=( "${tests[@]/#/$prefix}" )
25 result=$(_concatSep "and" prefixed)
26 echo "$result"
27}
28
29function pytestCheckPhase() {
30 echo "Executing pytestCheckPhase"
31 runHook preCheck
32
33 # Compose arguments
34 args=" -m pytest"
35 if [ -n "$disabledTests" ]; then
36 disabledTestsString=$(_pytestComputeDisabledTestsString "${disabledTests[@]}")
37 args+=" -k \""$disabledTestsString"\""
38 fi
39 args+=" ${pytestFlagsArray[@]}"
40 eval "@pythonCheckInterpreter@ $args"
41
42 runHook postCheck
43 echo "Finished executing pytestCheckPhase"
44}
45
46if [ -z "${dontUsePytestCheck-}" ] && [ -z "${installCheckPhase-}" ]; then
47 echo "Using pytestCheckPhase"
48 preDistPhases+=" pytestCheckPhase"
49fi