Newer
Older
# vim: set shiftwidth=4 softtabstop=4:

Vincent Hatakeyama
committed
#
# This script is used to run tests on a database with demo data installed.
#
# Either provide the name of the database (first argument) or it will default to <project>_test
# The DB user can be overridden by setting ODOO_SCRIPTS_DB_USER.

Vincent Hatakeyama
committed
# The environment variable “odoo_scripts_run_tests_logfile” can be set to be used to include the output of the tests

Vincent Hatakeyama
committed
here=$(dirname $0)
tested_modules=${ODOO_SCRIPTS_MODULE_LIST_TESTS-$(read_odoo_scripts_expandable_configuration_key module_list_tests)}
if [[ "$tested_modules" != "" ]];
then

Vincent Hatakeyama
committed
if [[ "$COVERAGE_SOURCE" == "" ]];
then
if type python3 > /dev/null;
then
COVERAGE_SOURCE="$(python3 -B -c "print(f','.join(f'odoo.addons.{name}' for name in '$tested_modules'.split(',')))")"
else
COVERAGE_SOURCE="$(python2 -B -c "print(','.join('odoo.addons.{}'.format(name) for name in '$tested_modules'.split(',')))")"
fi
fi

Vincent Hatakeyama
committed
dbname=$(basename $(readlink -f $project_home))_test

Vincent Hatakeyama
committed
shift
echo "$INFO Using database $dbname for tests"
if [[ -n "$ODOO_SCRIPTS_DB_USER" ]]
then
echo "$INFO Using db user $ODOO_SCRIPTS_DB_USER"
db_user_param="--db_user $ODOO_SCRIPTS_DB_USER"
fi

Vincent Hatakeyama
committed
if [ "$ODOO_TYPE" = "odoo8" ];
then
loglevel="--log-level=info"
else
loglevel="--log-level=test"
fi

Vincent Hatakeyama
committed
if [[ -z "$odoo_scripts_run_tests_logfile" ]];
then
logfile=$(mktemp --suffix=.log)
function clean_logfile() {
rm $logfile
}
trap clean_logfile INT TERM
else
logfile=$odoo_scripts_run_tests_logfile
fi
COVERAGE_SOURCE="${COVERAGE_SOURCE-$project_home}"

Vincent Hatakeyama
committed
if [ "$ODOO_TYPE" = "odoo7" ] || [ "$ODOO_TYPE" = "odoo8" ] || [ "$ODOO_TYPE" = "odoo9" ] || [ "$ODOO_TYPE" = "odoo10" ] ;

Vincent Hatakeyama
committed
# no coverage in those old versions
else
export PRE_ODOO_BIN="coverage run --omit='**/__manifest__.py' --source=$COVERAGE_SOURCE --branch "

Vincent Hatakeyama
committed
# Catch both stdout & stderr here as Odoo 10 uses stderr, unlike previous Odoo versions.
env odoo_scripts_start_logfile=$logfile $here/start $update -d $dbname $db_user_param --test-enable $loglevel --max-cron=0 --workers=0 --stop-after-init $* 2>&1 | colorize
start_status=$pipestatus[1]
analyze $logfile && return_code=0 || return_code=$?
echo "$FATAL Tests failed (exit ${start_status})"