incubator-airflow/run_unit_tests.sh

72 строки
2.1 KiB
Bash
Исходник Обычный вид История

#!/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.
set -x
# environment
export AIRFLOW_HOME=${AIRFLOW_HOME:=~}
[AIRFLOW-328][AIRFLOW-371] Remove redundant default configuration & fix unit test configuration AIRFLOW-328 https://issues.apache.org/jira/browse/AIRFLOW-328 Previously, Airflow had both a default template for airflow.cfg AND a dictionary of default values. Frequently, these get out of sync (an option in one has a different value than in the other, or isn’t present in the other). This commit removes the default dict and uses the airflow.cfg template to provide defaults. The ConfigParser first reads the template, loading all the options it contains, and then reads the user’s actual airflow.cfg to overwrite the default values with any new ones. AIRFLOW-371 https://issues.apache.org/jira/browse/AIRFLOW-371 Calling test_mode() didn't actually change Airflow's configuration! This actually wasn't an issue in unit tests because the unit test run script was hardcoded to point at the unittest.cfg file, but it needed to be fixed. [AIRFLOW-328] Remove redundant default configuration Previously, Airflow had both a default template for airflow.cfg AND a dictionary of default values. Frequently, these get out of sync (an option in one has a different value than in the other, or isn’t present in the other). This commit removes the default dict and uses the airflow.cfg template to provide defaults. The ConfigParser first reads the template, loading all the options it contains, and then reads the user’s actual airflow.cfg to overwrite the default values with any new ones. [AIRFLOW-371] Make test_mode() functional Previously, calling test_mode() didn’t actually do anything. This PR renames it to load_test_config() (to avoid confusion, ht @r39132). In addition, manually entering test_mode after Airflow launches might be too late — some options have already been loaded (DAGS_FOLDER, etc.). This makes it so setting tests/unit_test_mode OR the equivalent env var (AIRFLOW__TESTS__UNIT_TEST_MODE) will load the test config immediately, prior to loading the rest of Airflow. Closes #1677 from jlowin/Simplify-config
2016-08-12 20:34:50 +03:00
export AIRFLOW__CORE__UNIT_TEST_MODE=True
# add test/contrib to PYTHONPATH
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export PYTHONPATH=$PYTHONPATH:${DIR}/tests/test_utils
# any argument received is overriding the default nose execution arguments:
nose_args=$@
# Generate the `airflow` executable if needed
which airflow > /dev/null || python setup.py develop
2015-10-18 00:04:56 +03:00
echo "Initializing the DB"
yes | airflow initdb
yes | airflow resetdb
if [ -z "$nose_args" ]; 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
# For impersonation tests running on SQLite on Travis, make the database world readable so other
# users can update it
AIRFLOW_DB="$HOME/airflow.db"
if [ -f "${AIRFLOW_DB}" ]; then
chmod a+rw "${AIRFLOW_DB}"
chmod g+rwx "${AIRFLOW_HOME}"
fi
# For impersonation tests on Travis, make airflow accessible to other users via the global PATH
# (which contains /usr/local/bin)
sudo ln -sf "${VIRTUAL_ENV}/bin/airflow" /usr/local/bin/
echo "Starting the unit tests with the following nose arguments: "$nose_args
nosetests $nose_args
2015-06-05 20:41:36 +03:00
# To run individual tests:
# nosetests tests.core:CoreTest.test_scheduler_job