forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-tests
executable file
·181 lines (150 loc) · 4.64 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
#!/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")"
AIRFLOW_ROOT="$(cd "${MY_DIR}" && pwd)"
export AIRFLOW__CORE__DAGS_FOLDER="S{AIRFLOW_ROOT}/tests/dags"
# environment
export AIRFLOW_HOME=${AIRFLOW_HOME:=${HOME}}
echo "Airflow home: ${AIRFLOW_HOME}"
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
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
-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 "h i s v" \
-l "help with-db-init nocapture verbose" \
--name "${CMDNAME}" -- "$@")
then
usage
exit 1
fi
eval set -- "${PARAMS}"
unset PARAMS
WITH_DB_INIT="false"
NOCAPTURE="false"
VERBOSE="false"
# 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 ;;
-v|--verbose)
VERBOSE="true"
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 db init || true
airflow db reset -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/static/coverage"
"--with-ignore-docstrings"
"--rednose"
"--with-timer"
"-v"
"--logging-level=DEBUG")
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[@]}"
set -u