github.com/apache/beam/sdks/v2@v2.48.2/python/scripts/run_pytest.sh (about) 1 #!/bin/bash 2 # 3 # Licensed to the Apache Software Foundation (ASF) under one or more 4 # contributor license agreements. See the NOTICE file distributed with 5 # this work for additional information regarding copyright ownership. 6 # The ASF licenses this file to You under the Apache License, Version 2.0 7 # (the "License"); you may not use this file except in compliance with 8 # the License. You may obtain a copy of the License at 9 # 10 # http://www.apache.org/licenses/LICENSE-2.0 11 # 12 # Unless required by applicable law or agreed to in writing, software 13 # distributed under the License is distributed on an "AS IS" BASIS, 14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 # See the License for the specific language governing permissions and 16 # limitations under the License. 17 # 18 # Utility script for tox.ini for running unit tests. 19 # 20 # Runs tests in parallel, except those not compatible with xdist. Combines 21 # exit statuses of runs, special-casing 5, which says that no tests were 22 # selected. 23 # 24 # $1 - suite base name 25 # $2 - additional arguments not parsed by tox (typically module names or 26 # '-k keyword') 27 # $3 - optional arguments to pytest 28 29 envname=${1?First argument required: suite base name} 30 posargs=$2 31 pytest_args=$3 32 33 if [[ $pytest_args =~ "-m" ]] || [[ $posargs =~ "-m" ]]; then 34 echo "$0 cannot be called with -m as it interferes with 'no_xdist' logic, see BEAM-12985." 35 exit 1 36 fi 37 38 # strip leading/trailing quotes from posargs because it can get double quoted as its passed through. 39 posargs=$(sed -e 's/^"//' -e 's/"$//' -e "s/'$//" -e "s/^'//" <<<$posargs) 40 echo "pytest_args: $pytest_args" 41 echo "posargs: $posargs" 42 43 # Run with pytest-xdist and without. 44 pytest -o junit_suite_name=${envname} \ 45 --junitxml=pytest_${envname}.xml -m 'not no_xdist' -n 6 ${pytest_args} --pyargs ${posargs} 46 status1=$? 47 pytest -o junit_suite_name=${envname}_no_xdist \ 48 --junitxml=pytest_${envname}_no_xdist.xml -m 'no_xdist' ${pytest_args} --pyargs ${posargs} 49 status2=$? 50 51 # Exit with error if no tests were run in either suite (status code 5). 52 if [[ $status1 == 5 && $status2 == 5 ]]; then 53 exit $status1 54 fi 55 56 # Exit with error if one of the statuses has an error that's not 5. 57 if [[ $status1 != 0 && $status1 != 5 ]]; then 58 exit $status1 59 fi 60 if [[ $status2 != 0 && $status2 != 5 ]]; then 61 exit $status2 62 fi