From 342b8362ee4593f23d794df4058d08baca3645d3 Mon Sep 17 00:00:00 2001 From: Brad Hall Date: Mon, 26 Sep 2011 17:18:34 -0700 Subject: [PATCH] Add code-coverage support to run_tests.sh (lp860160) Change-Id: I404ba58ea882123b8c6669ea32923fa626b27de5 --- quantum/common/test_lib.py | 1 + run_tests.py | 4 +++- run_tests.sh | 26 ++++++++++++++++++++++++-- tools/pip-requires | 2 ++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/quantum/common/test_lib.py b/quantum/common/test_lib.py index 2ccd681ce..a84eb77d3 100644 --- a/quantum/common/test_lib.py +++ b/quantum/common/test_lib.py @@ -167,6 +167,7 @@ class QuantumTestResult(result.TextTestResult): self.colorizer = None # NOTE(vish, tfukushima): reset stdout for the terminal check stdout = sys.__stdout__ + sys.stdout = sys.__stdout__ for colorizer in [_Win32Colorizer, _AnsiColorizer, _NullColorizer]: if colorizer.supported(): self.colorizer = colorizer(self.stream) diff --git a/run_tests.py b/run_tests.py index d73c0d518..34d56c502 100644 --- a/run_tests.py +++ b/run_tests.py @@ -48,6 +48,7 @@ import sys from quantum.common.test_lib import run_tests from nose import config +from nose import core if __name__ == '__main__': @@ -55,5 +56,6 @@ if __name__ == '__main__': c = config.Config(stream=sys.stdout, env=os.environ, verbosity=3, - workingDir=working_dir) + workingDir=working_dir, + plugins=core.DefaultPluginManager()) sys.exit(run_tests(c)) diff --git a/run_tests.sh b/run_tests.sh index 1f5a94b98..aee422a62 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -6,6 +6,7 @@ function usage { echo "" echo " -V, --virtual-env Always use virtualenv. Install automatically if not present" echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment" + echo " -c, --coverage Generate coverage report" echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added." echo " -h, --help Print this usage message" echo "" @@ -21,6 +22,8 @@ function process_option { -V|--virtual-env) let always_venv=1; let never_venv=0;; -N|--no-virtual-env) let always_venv=0; let never_venv=1;; -f|--force) let force=1;; + -c|--coverage) coverage=1;; + -*) noseopts="$noseopts $1";; *) noseargs="$noseargs $1" esac } @@ -32,18 +35,24 @@ never_venv=0 force=0 noseargs= wrapper="" +coverage=0 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=quantum" +fi + function run_tests { # Just run the test suites in current environment ${wrapper} rm -f ./$PLUGIN_DIR/tests.sqlite ${wrapper} $NOSETESTS } -NOSETESTS="python ./$PLUGIN_DIR/run_tests.py $noseargs" +NOSETESTS="python ./$PLUGIN_DIR/run_tests.py $noseopts $noseargs" if [ -n "$PLUGIN_DIR" ] then @@ -80,6 +89,11 @@ then fi fi +# Delete old coverage data from previous runs +if [ $coverage -eq 1 ]; then + ${wrapper} coverage erase +fi + # FIXME(sirp): bzr version-info is not currently pep-8. This was fixed with # lp701898 [1], however, until that version of bzr becomes standard, I'm just # excluding the vcsversion.py file @@ -89,4 +103,12 @@ fi PEP8_EXCLUDE=vcsversion.py PEP8_OPTIONS="--exclude=$PEP8_EXCLUDE --repeat --show-source" PEP8_INCLUDE="bin/* quantum tests tools run_tests.py" -run_tests && pep8 $PEP8_OPTIONS $PEP8_INCLUDE || exit 1 +RV=0 +run_tests && pep8 $PEP8_OPTIONS $PEP8_INCLUDE || RV=1 + +if [ $coverage -eq 1 ]; then + echo "Generating coverage report in covhtml/" + ${wrapper} coverage html -d covhtml -i +fi + +exit $RV diff --git a/tools/pip-requires b/tools/pip-requires index 31b66c77f..4cdeae822 100644 --- a/tools/pip-requires +++ b/tools/pip-requires @@ -1,6 +1,8 @@ +coverage eventlet>=0.9.12 Routes>=1.12.3 nose +nosexcover Paste PasteDeploy pep8>=0.5.0