diff --git a/.testr.conf b/.testr.conf deleted file mode 100755 index 077512e83a..0000000000 --- a/.testr.conf +++ /dev/null @@ -1,8 +0,0 @@ -[DEFAULT] -test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ - OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ - OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \ - ${PYTHON:-python} -m subunit.run discover $DISCOVER_DIRECTORY $LISTOPT $IDOPTION -test_id_option=--load-list $IDFILE -test_list_option=--list -group_regex=([^\.]+\.)+ diff --git a/lower-constraints.txt b/lower-constraints.txt index eec2ba449a..bd9e81412a 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -146,7 +146,6 @@ stestr==1.0.0 stevedore==1.20.0 Tempita==0.5.2 tenacity==4.9.0 -testrepository==0.0.20 testresources==2.0.0 testscenarios==0.4 testtools==2.2.0 diff --git a/tools/cover.sh b/tools/cover.sh index 9b24e7df99..ac3ddbf380 100755 --- a/tools/cover.sh +++ b/tools/cover.sh @@ -22,15 +22,24 @@ show_diff () { diff -U 0 $1 $2 | sed 1,2d } +package_name=${PACKAGE_NAME:-sahara} +export PYTHON="coverage run --source ${package_name} --parallel-mode" + +run_coverage () { + find . -type f -name "*.pyc" -delete && coverage erase && \ + stestr run "$*" + coverage combine +} + # Stash uncommitted changes, checkout master and save coverage report uncommitted=$(git status --porcelain | grep -v "^??") [[ -n $uncommitted ]] && git stash > /dev/null git checkout HEAD^ baseline_report=$(mktemp -t sahara_coverageXXXXXXX) -find . -type f -name "*.pyc" -delete && python setup.py testr --coverage --testr-args="$*" +run_coverage "$*" coverage report > $baseline_report -baseline_missing=$(awk 'END { print $3 }' $baseline_report) +baseline_missing=$(awk '/^TOTAL/ { print $3 }' $baseline_report) # Checkout back and unstash uncommitted changes (if any) git checkout - @@ -38,9 +47,12 @@ git checkout - # Generate and save coverage report current_report=$(mktemp -t sahara_coverageXXXXXXX) -find . -type f -name "*.pyc" -delete && python setup.py testr --coverage --testr-args="$*" +run_coverage "$*" coverage report > $current_report -current_missing=$(awk 'END { print $3 }' $current_report) +current_missing=$(awk '/^TOTAL/ { print $3 }' $current_report) + +coverage html -d cover +coverage xml -o cover/coverage.xml # Show coverage details allowed_missing=$((baseline_missing+ALLOWED_EXTRA_MISSING)) @@ -49,7 +61,10 @@ echo "Allowed to introduce missing lines : ${ALLOWED_EXTRA_MISSING}" echo "Missing lines in master : ${baseline_missing}" echo "Missing lines in proposed change : ${current_missing}" -if [ $allowed_missing -gt $current_missing ]; +if [ -z "$current_missing" ]; then + echo "No coverage found!" + exit_code=1 +elif [ $allowed_missing -gt $current_missing ]; then if [ $baseline_missing -lt $current_missing ]; then @@ -66,4 +81,5 @@ else fi rm $baseline_report $current_report + exit $exit_code diff --git a/tox.ini b/tox.ini index e9ff9aec98..25aed17f40 100644 --- a/tox.ini +++ b/tox.ini @@ -17,6 +17,8 @@ passenv = http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY [testenv:cover] basepython = python3 +setenv = + PACKAGE_NAME=sahara commands = {toxinidir}/tools/cover.sh {posargs} [testenv:debug-py27]