diff options
author | Monty Taylor <mordred@inaugust.com> | 2012-12-25 00:02:54 -0600 |
---|---|---|
committer | Clark Boylan <clark.boylan@gmail.com> | 2013-05-10 15:39:10 -0700 |
commit | 11263ac3186e1ccfce0d59592d64b6857673601d (patch) | |
tree | 61a38cbdf9b355bf9443d80feea83ab79a5bfb90 /run_tests.sh | |
parent | 548b52336f19ea91dde3076ff85dbce9735f5420 (diff) | |
download | python-keystoneclient-11263ac3186e1ccfce0d59592d64b6857673601d.tar.gz |
Use testr instead of nose.
Part of blueprint grizzly-testtools
Change-Id: I76dee19781eaac21901b5c0258e83a42180c1702
Diffstat (limited to 'run_tests.sh')
-rwxr-xr-x | run_tests.sh | 90 |
1 files changed, 70 insertions, 20 deletions
diff --git a/run_tests.sh b/run_tests.sh index 782c365..12ed568 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -14,6 +14,7 @@ function usage { echo " -p, --pep8 Just run pep8" echo " -P, --no-pep8 Don't run pep8" echo " -c, --coverage Generate coverage report" + echo " -d, --debug Run tests with testtools instead of testr. This allows you to use the debugger." echo " -h, --help Print this usage message" echo " --hide-elapsed Don't print the elapsed time for each test along with slow test list" echo "" @@ -33,8 +34,9 @@ function process_option { -p|--pep8) just_pep8=1;; -P|--no-pep8) no_pep8=1;; -c|--coverage) coverage=1;; - -*) noseopts="$noseopts $1";; - *) noseargs="$noseargs $1" + -d|--debug) debug=1;; + -*) testropts="$testropts $1";; + *) testrargs="$testrargs $1" esac } @@ -45,34 +47,86 @@ never_venv=0 force=0 no_site_packages=0 installvenvopts= -noseargs= -noseopts= +testrargs= +testropts= wrapper="" just_pep8=0 no_pep8=0 coverage=0 +debug=0 + +LANG=en_US.UTF-8 +LANGUAGE=en_US:en +LC_ALL=C +OS_STDOUT_NOCAPTURE=False +OS_STDERR_NOCAPTURE=False for arg in "$@"; do process_option $arg done -# If enabled, tell nose to collect coverage data -if [ $coverage -eq 1 ]; then - noseopts="$noseopts --with-coverage --cover-package=keystoneclient" -fi - if [ $no_site_packages -eq 1 ]; then installvenvopts="--no-site-packages" fi +function init_testr { + if [ ! -d .testrepository ]; then + ${wrapper} testr init + fi +} + function run_tests { + # Cleanup *.pyc + ${wrapper} find . -type f -name "*.pyc" -delete + + if [ $debug -eq 1 ]; then + if [ "$testropts" = "" ] && [ "$testrargs" = "" ]; then + # Default to running all tests if specific test is not + # provided. + testrargs="discover ./tests" + fi + ${wrapper} python -m testtools.run $testropts $testrargs + + # Short circuit because all of the testr and coverage stuff + # below does not make sense when running testtools.run for + # debugging purposes. + return $? + fi + + if [ $coverage -eq 1 ]; then + TESTRTESTS="$TESTRTESTS --coverage" + else + TESTRTESTS="$TESTRTESTS" + fi + # Just run the test suites in current environment - ${wrapper} $NOSETESTS - # If we get some short import error right away, print the error log directly + set +e + testrargs=`echo "$testrargs" | sed -e's/^\s*\(.*\)\s*$/\1/'` + TESTRTESTS="$TESTRTESTS --testr-args='$testropts $testrargs'" + echo "Running \`${wrapper} $TESTRTESTS\`" + bash -c "${wrapper} $TESTRTESTS" RESULT=$? + set -e + + copy_subunit_log + + if [ $coverage -eq 1 ]; then + echo "Generating coverage report in covhtml/" + # Don't compute coverage for common code, which is tested elsewhere + ${wrapper} coverage combine + ${wrapper} coverage html --include='keystoneclient/*' --omit='keystoneclient/openstack/common/*' -d covhtml -i + fi + return $RESULT } +function copy_subunit_log { + LOGNAME=`cat .testrepository/next-stream` + LOGNAME=$(($LOGNAME - 1)) + LOGNAME=".testrepository/${LOGNAME}" + cp $LOGNAME subunit.log +} + function run_pep8 { echo "Running pep8 ..." srcfiles="keystoneclient tests" @@ -85,7 +139,7 @@ function run_pep8 { ${srcfiles} } -NOSETESTS="nosetests $noseopts $noseargs" +TESTRTESTS="python setup.py testr" if [ $never_venv -eq 0 ] then @@ -123,19 +177,15 @@ if [ $just_pep8 -eq 1 ]; then exit fi +init_testr run_tests # NOTE(sirp): we only want to run pep8 when we're running the full-test suite, # not when we're running tests individually. To handle this, we need to -# distinguish between options (noseopts), which begin with a '-', and -# arguments (noseargs). -if [ -z "$noseargs" ]; then +# distinguish between options (testropts), which begin with a '-', and +# arguments (testrargs). +if [ -z "$testrargs" ]; then if [ $no_pep8 -eq 0 ]; then run_pep8 fi fi - -if [ $coverage -eq 1 ]; then - echo "Generating coverage report in covhtml/" - ${wrapper} coverage html -d covhtml -i -fi |