From c11108a6e3e0728864688cbcd3c29484b02354d7 Mon Sep 17 00:00:00 2001 From: Alexander Maretskiy Date: Mon, 27 Jun 2016 12:25:50 +0300 Subject: [PATCH] [CI] Fix coverage job Changes: * start using pytest-cov library * if there are uncommitted changes then do not try to stash them automatically but exit with error message Co-Authored-By: Andrey Kurilin Co-Authored-By: Alexander Maretskiy Change-Id: Id5f396550a600fe0ab899b09aceff60b3d98dc0e --- .coveragerc | 3 +++ test-requirements.txt | 1 + tests/ci/cover.sh | 20 ++++++++++++-------- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.coveragerc b/.coveragerc index 302abb04e5..733bacb426 100644 --- a/.coveragerc +++ b/.coveragerc @@ -6,3 +6,6 @@ source = rally ignore_errors = True precision = 3 omit = */migrations/versions/ca3626f62937_init_migration.py + +[html] +directory = cover diff --git a/test-requirements.txt b/test-requirements.txt index 4abcc03deb..f00a80bfbd 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -3,6 +3,7 @@ # process, which may cause wedges in the gate later. hacking<0.10,>=0.9.2 pytest>=2.7 +pytest-cov>=2.2.1 pytest-html coverage>=3.6 # Apache-2.0 diff --git a/tests/ci/cover.sh b/tests/ci/cover.sh index e9d9b0a4d4..72cc370992 100755 --- a/tests/ci/cover.sh +++ b/tests/ci/cover.sh @@ -22,24 +22,28 @@ show_diff () { diff -U 0 $1 $2 | sed 1,2d } -# Stash uncommitted changes, checkout master and save coverage report -uncommited=$(git status --porcelain | grep -v "^??") -[[ -n $uncommited ]] && git stash > /dev/null +if ! git diff --exit-code || ! git diff --cached --exit-code +then + echo "There are uncommited changes!" + echo "Please clean git working directory and try again" + exit 1 +fi + +# Checkout master and save coverage report git checkout HEAD^ baseline_report=$(mktemp -t rally_coverageXXXXXXX) -find . -type f -name "*.pyc" -delete && python setup.py testr --coverage --testr-args="$*" +py.test --cov=rally tests/unit/ --cov-report=html coverage report > $baseline_report +mv cover cover-master cat $baseline_report baseline_missing=$(awk 'END { print $3 }' $baseline_report) -# Checkout back and unstash uncommitted changes (if any) +# Checkout back and save coverage report git checkout - -[[ -n $uncommited ]] && git stash pop > /dev/null -# Generate and save coverage report current_report=$(mktemp -t rally_coverageXXXXXXX) -find . -type f -name "*.pyc" -delete && python setup.py testr --coverage --testr-args="$*" +py.test --cov=rally tests/unit/ --cov-report=html coverage report > $current_report current_missing=$(awk 'END { print $3 }' $current_report)