1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#!/bin/bash
# Copyright 2022 Julian Gilbey <jdg@debian.org>
# License: MIT License
# Determine whether every test passes in at least one pytest run.
# We run the command given on the command line at most MAX_PYTEST_RUNS,
# stopping if a pytest run is successful.
get_exclusions_script=$1
shift
interpreter=$1
exclusions=$($get_exclusions_script $interpreter)
MAX_PYTEST_RUNS=5
NO_TESTS_EXITCODE=$(python3 -c "from pytest import ExitCode; print(int(ExitCode.NO_TESTS_COLLECTED))")
# Remove any old log files
rm -f pytest_log.txt
run=1
# We use the --numprocesses=1 flag after the first run, in case parallelism
# causes some tests to fail
# We first check to see if the number of processes is specified in
# DEB_BUILD_OPTIONS, otherwise we will use "auto"
njobs=auto
for flag in $DEB_BUILD_OPTIONS
do
case "$flag" in
parallel) njobs=auto ;;
parallel=*) njobs=${flag#parallel=} ;;
*) ;;
esac
done
njobsflag="--numprocesses=$njobs"
while [ $run -le $MAX_PYTEST_RUNS ]
do
echo "*** STARTING RUN $run: $* $njobsflag $exclusions"
set -o pipefail
"$@" $njobsflag $exclusions | tee -a pytest_log.txt
ret=$?
set +o pipefail
if [ $ret -eq 0 -o $ret -eq $NO_TESTS_EXITCODE ]
then
echo "*** END OF RUN $run: ALL TESTS RUN HAVE NOW PASSED/XFAILED ***"
rm -f pytest_log.txt
exit 0
fi
echo "*** END OF RUN $run: NOT ALL TESTS HAVE YET PASSED/XFAILED ***"
run=$(($run + 1))
njobsflag="--numprocesses=1"
done
echo "*** SOME TESTS FAILED/ERRORED EVERY RUN, ABORTING ***"
rm -f pytest_log.txt
exit 1
|