blob: a12bf468af98b7f7edf755f15505fab6e0f95436 [file] [log] [blame]
Attila Fazekas5abb2532012-12-04 11:30:49 +01001#!/usr/bin/env bash
Justin Shepherd0d9bbd12011-08-11 12:57:44 -05002
3function usage {
Jay Pipesf38eaac2012-06-21 13:37:35 -04004 echo "Usage: $0 [OPTION]..."
Matthew Treinish17520e42014-01-05 13:02:23 -05005 echo "Run Tempest unit tests"
Justin Shepherd0d9bbd12011-08-11 12:57:44 -05006 echo ""
Matthew Treinish8e937d72012-12-14 11:11:41 -05007 echo " -V, --virtual-env Always use virtualenv. Install automatically if not present"
8 echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment"
Andrea Frittoli1cfbc4a2013-01-31 19:44:10 +00009 echo " -n, --no-site-packages Isolate the virtualenv from the global Python environment"
Matthew Treinish8e937d72012-12-14 11:11:41 -050010 echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
Matthew Treinish8f42d3b2013-02-15 13:24:05 -050011 echo " -u, --update Update the virtual environment with any newer package versions"
Matthew Treinish49f40362013-08-27 16:02:53 -040012 echo " -t, --serial Run testr serially"
Jay Pipesf38eaac2012-06-21 13:37:35 -040013 echo " -p, --pep8 Just run pep8"
Matthew Treinishab836be2014-01-11 14:34:58 -050014 echo " -c, --coverage Generate coverage report"
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050015 echo " -h, --help Print this usage message"
Matthew Treinish1b1eb642014-01-21 19:38:47 +000016 echo " -d, --debug Run tests with testtools instead of testr. This allows you to use PDB"
Matthew Treinish59eb0b22013-08-07 15:48:21 -040017 echo " -- [TESTROPTIONS] After the first '--' you can pass arbitrary arguments to testr "
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050018}
19
Matthew Treinish59eb0b22013-08-07 15:48:21 -040020testrargs=""
Jay Pipesf38eaac2012-06-21 13:37:35 -040021just_pep8=0
Matthew Treinish8e937d72012-12-14 11:11:41 -050022venv=.venv
23with_venv=tools/with_venv.sh
Matthew Treinish49f40362013-08-27 16:02:53 -040024serial=0
Matthew Treinish8e937d72012-12-14 11:11:41 -050025always_venv=0
26never_venv=0
27no_site_packages=0
Matthew Treinish1b1eb642014-01-21 19:38:47 +000028debug=0
Matthew Treinish8e937d72012-12-14 11:11:41 -050029force=0
Matthew Treinishab836be2014-01-11 14:34:58 -050030coverage=0
Matthew Treinish8e937d72012-12-14 11:11:41 -050031wrapper=""
Attila Fazekasa63a9992013-02-14 16:44:37 +010032config_file=""
Matthew Treinish8f42d3b2013-02-15 13:24:05 -050033update=0
Attila Fazekasa63a9992013-02-14 16:44:37 +010034
Matthew Treinishab836be2014-01-11 14:34:58 -050035if ! options=$(getopt -o VNnfuctphd -l virtual-env,no-virtual-env,no-site-packages,force,update,serial,coverage,pep8,help,debug -- "$@")
Attila Fazekasa63a9992013-02-14 16:44:37 +010036then
37 # parse error
38 usage
39 exit 1
40fi
41
42eval set -- $options
43first_uu=yes
44while [ $# -gt 0 ]; do
45 case "$1" in
46 -h|--help) usage; exit;;
47 -V|--virtual-env) always_venv=1; never_venv=0;;
48 -N|--no-virtual-env) always_venv=0; never_venv=1;;
49 -n|--no-site-packages) no_site_packages=1;;
50 -f|--force) force=1;;
Matthew Treinish8f42d3b2013-02-15 13:24:05 -050051 -u|--update) update=1;;
Matthew Treinish1b1eb642014-01-21 19:38:47 +000052 -d|--debug) debug=1;;
Attila Fazekasa63a9992013-02-14 16:44:37 +010053 -p|--pep8) let just_pep8=1;;
Matthew Treinishab836be2014-01-11 14:34:58 -050054 -c|--coverage) coverage=1;;
Matthew Treinish49f40362013-08-27 16:02:53 -040055 -t|--serial) serial=1;;
Matthew Treinish59eb0b22013-08-07 15:48:21 -040056 --) [ "yes" == "$first_uu" ] || testrargs="$testrargs $1"; first_uu=no ;;
Matthew Treinisha74f5d42014-02-07 20:25:44 -050057 *) testrargs="$testrargs $1";;
Attila Fazekasa63a9992013-02-14 16:44:37 +010058 esac
59 shift
60done
61
Mitsuhiko Yamazaki46818aa2013-04-18 17:49:17 +090062
Attila Fazekasa63a9992013-02-14 16:44:37 +010063cd `dirname "$0"`
Jay Pipesf38eaac2012-06-21 13:37:35 -040064
Matthew Treinish8e937d72012-12-14 11:11:41 -050065if [ $no_site_packages -eq 1 ]; then
66 installvenvopts="--no-site-packages"
67fi
Sean Dague422af972012-11-16 07:30:43 -050068
Matthew Treinish87af1bb2013-06-17 15:29:10 -040069function testr_init {
70 if [ ! -d .testrepository ]; then
71 ${wrapper} testr init
72 fi
73}
74
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050075function run_tests {
Matthew Treinish59eb0b22013-08-07 15:48:21 -040076 testr_init
77 ${wrapper} find . -type f -name "*.pyc" -delete
Matthew Treinish17520e42014-01-05 13:02:23 -050078 export OS_TEST_PATH=./tempest/tests
Matthew Treinish1b1eb642014-01-21 19:38:47 +000079 if [ $debug -eq 1 ]; then
80 if [ "$testrargs" = "" ]; then
81 testrargs="discover ./tempest/tests"
82 fi
83 ${wrapper} python -m testtools.run $testrargs
84 return $?
85 fi
86
Matthew Treinish95817e02014-02-11 19:29:48 +000087 if [ $coverage -eq 1 ]; then
88 ${wrapper} python setup.py test --coverage
89 return $?
90 fi
91
Matthew Treinish49f40362013-08-27 16:02:53 -040092 if [ $serial -eq 1 ]; then
Matthew Treinish59eb0b22013-08-07 15:48:21 -040093 ${wrapper} testr run --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
Matthew Treinish49f40362013-08-27 16:02:53 -040094 else
95 ${wrapper} testr run --parallel --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
Matthew Treinish87af1bb2013-06-17 15:29:10 -040096 fi
Justin Shepherd0d9bbd12011-08-11 12:57:44 -050097}
98
Jay Pipesf38eaac2012-06-21 13:37:35 -040099function run_pep8 {
Kui Shib1b7c712013-08-23 06:40:05 +0800100 echo "Running flake8 ..."
101 if [ $never_venv -eq 1 ]; then
102 echo "**WARNING**:" >&2
103 echo "Running flake8 without virtual env may miss OpenStack HACKING detection" >&2
104 fi
Monty Taylorb2ca5ca2013-04-28 18:00:21 -0700105 ${wrapper} flake8
Masayuki Igawa7c40afa2014-02-05 16:15:07 +0900106 export MODULEPATH=tempest.common.generate_sample_tempest
107 ${wrapper} tools/config/check_uptodate.sh
Jay Pipesf38eaac2012-06-21 13:37:35 -0400108}
109
Matthew Treinish8e937d72012-12-14 11:11:41 -0500110if [ $never_venv -eq 0 ]
111then
112 # Remove the virtual environment if --force used
113 if [ $force -eq 1 ]; then
114 echo "Cleaning virtualenv..."
115 rm -rf ${venv}
116 fi
Matthew Treinish8f42d3b2013-02-15 13:24:05 -0500117 if [ $update -eq 1 ]; then
118 echo "Updating virtualenv..."
119 python tools/install_venv.py $installvenvopts
120 fi
Matthew Treinish8e937d72012-12-14 11:11:41 -0500121 if [ -e ${venv} ]; then
122 wrapper="${with_venv}"
123 else
124 if [ $always_venv -eq 1 ]; then
125 # Automatically install the virtualenv
126 python tools/install_venv.py $installvenvopts
127 wrapper="${with_venv}"
128 else
129 echo -e "No virtual environment found...create one? (Y/n) \c"
130 read use_ve
131 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
132 # Install the virtualenv and run the test suite in it
133 python tools/install_venv.py $installvenvopts
134 wrapper=${with_venv}
135 fi
136 fi
137 fi
138fi
139
Matthew Treinish0cc26b62013-01-03 18:07:09 -0500140if [ $just_pep8 -eq 1 ]; then
141 run_pep8
142 exit
143fi
144
Matthew Treinish17520e42014-01-05 13:02:23 -0500145run_tests
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200146retval=$?
Matthew Treinishd15705b2012-10-16 14:04:48 -0400147
Matthew Treinish59eb0b22013-08-07 15:48:21 -0400148if [ -z "$testrargs" ]; then
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200149 run_pep8
Jay Pipesf38eaac2012-06-21 13:37:35 -0400150fi
Giulio Fidente1e50b3b2013-06-03 15:00:54 +0200151
152exit $retval