forked from Zomato/airflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-tests
executable file
·218 lines (180 loc) · 5.77 KB
/
run-tests
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
MY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Bash sanity settings (error on exit, complain for undefined vars, error when pipe fails)
set -euo pipefail
CMDNAME="$(basename -- "$0")"
if [[ ${AIRFLOW_CI_VERBOSE:="false"} == "true" ]]; then
set -x
fi
if [[ -z "${AIRFLOW__CORE__SQL_ALCHEMY_CONN:=}" ]]; then
echo "AIRFLOW__CORE__SQL_ALCHEMY_CONN not set - using default" >&2
fi
# Update short and long options in the breeze-complete script
# This way autocomplete will work automagically with all options
# shellcheck source=run-tests-complete
. "${MY_DIR}/run-tests-complete"
# environment
export AIRFLOW_HOME=${AIRFLOW_HOME:=${HOME}}
AIRFLOW_ROOT="$(cd "${MY_DIR}" && pwd)"
export AIRFLOW_ROOT
export AIRFLOW__CORE__DAGS_FOLDER="S{AIRFLOW_ROOT}/tests/dags"
export AIRFLOW__CORE__UNIT_TEST_MODE=True
# add test/test_utils to PYTHONPATH TODO: Do we need that ??? Looks fishy.
export PYTHONPATH=${PYTHONPATH:=}:${AIRFLOW_ROOT}/tests/test_utils
echo Airflow home: "${AIRFLOW_HOME}"
echo Airflow root: "${AIRFLOW_ROOT}"
echo Home of the user: "${HOME}"
export AIRFLOW__CORE__DAGS_FOLDER="${AIRFLOW_ROOT}/tests/dags"
usage() {
echo """
Usage: ${CMDNAME} [FLAGS] [TESTS_TO_RUN] -- <EXTRA_NOSETEST_ARGS>
Runs tests specified (or all tests if no tests are specified)
Flags:
-h, --help
Shows this help message.
-i, --with-db-init
Forces database initialization before tests
-x, --with-xunit
Dumps result of the tests to Xunit file
-f, --xunit-file
The file where xunit results should be dumped. Default if not specified
is ${AIRFLOW_ROOT}/logs/all_tests.xml
-s, --nocapture
Don't capture stdout when running the tests. This is useful if you are
debugging with ipdb and want to drop into console with it
by adding this line to source code:
import ipdb; ipdb.set_trace()
-v, --verbose
Verbose output showing coloured output of tests being run and summary
of the tests - in a manner similar to the tests run in the CI environment.
"""
}
echo
#################### Parsing options/arguments
if ! PARAMS=$(getopt \
-o "${_RUN_TESTS_GETOPT_SHORT_OPTIONS:=}" \
-l "${_RUN_TESTS_GETOPT_LONG_OPTIONS:=}" \
--name "$CMDNAME" -- "$@")
then
usage
fi
eval set -- "${PARAMS}"
unset PARAMS
WITH_DB_INIT="false"
NOCAPTURE="false"
WITH_XUNIT="false"
XUNIT_FILE="${AIRFLOW_ROOT}/logs/all_tests.xml"
VERBOSE="${AIRFLOW_CI_VERBOSE}"
# Parse Flags.
# Please update short and long options in the run-tests-complete script
# This way autocomplete will work out-of-the-box
while true
do
case "${1}" in
-h|--help)
usage;
exit 0 ;;
-i|--with-db-init)
WITH_DB_INIT="true"
shift ;;
-s|--nocapture)
NOCAPTURE="true"
shift ;;
-x|--with-xunit)
WITH_XUNIT="true"
shift ;;
-v|--verbose)
VERBOSE="true"
shift;;
-f|--xunit-file)
XUNIT_FILE="$2"
shift; shift ;;
--)
shift ;
break ;;
*)
usage
echo
echo "ERROR: Unknown argument ${1}"
echo
exit 1
;;
esac
done
# any argument received after -- is overriding the default nose execution arguments:
NOSE_ARGS=("$@")
AIRFLOW_DB_INITIALISED_FILE=${HOME}/.airflow_db_initialised
if [[ "${WITH_DB_INIT}" == "true" || ! -f ${AIRFLOW_DB_INITIALISED_FILE} ]]; then
echo
if [[ "${WITH_DB_INIT}" == "true" ]]; then
echo "Initializing the DB - forced with --with-db-init switch"
else
echo "Initializing the DB - first time after entering the container"
echo "You can force re-initialization the database by adding --with-db-init switch to run-tests."
fi
echo
yes | airflow initdb || true
airflow resetdb -y
touch "${AIRFLOW_DB_INITIALISED_FILE}"
else
echo
echo "Skipping initializing of the DB as it was initialized already"
echo
echo "You can re-initialize the database by adding --with-db-init flag when running tests"
echo
fi
if [[ "${KRB5_KTNAME:=}" == "" ]]; then
echo "KRB5_KTNAME variable is empty - no kerberos intialisation"
else
kinit -kt "${KRB5_KTNAME}" airflow
fi
if [[ "${#NOSE_ARGS[@]}" == "0" ]]; then
NOSE_ARGS=("--with-coverage"
"--cover-erase"
"--cover-html"
"--cover-package=airflow"
"--cover-html-dir=airflow/www_rbac/static/coverage"
"--with-ignore-docstrings"
"--rednose"
"--with-timer"
"-v"
"--logging-level=DEBUG")
fi
if [[ "${WITH_XUNIT}" == "true" ]]; then
echo
echo "Dumping results to ${XUNIT_FILE}"
echo
NOSE_ARGS+=("--with-xunit" "--xunit-file=${XUNIT_FILE}")
fi
if [[ "${NOCAPTURE}" == "true" ]]; then
echo
echo "Stop capturing stdout"
echo
NOSE_ARGS+=("--nocapture")
fi
if [[ "${VERBOSE}" == "true" ]]; then
echo
echo "Verbose output"
echo
NOSE_ARGS+=("--rednose" "--with-timer" "-v" "--logging-level=DEBUG")
fi
echo
echo "Starting the tests with arguments: ${NOSE_ARGS[*]}"
echo
nosetests "${NOSE_ARGS[@]}"