]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add code-coverage support to run_tests.sh (lp860160)
authorBrad Hall <brad@nicira.com>
Tue, 27 Sep 2011 00:18:34 +0000 (17:18 -0700)
committerBrad Hall <brad@nicira.com>
Sun, 2 Oct 2011 22:46:29 +0000 (15:46 -0700)
Change-Id: I404ba58ea882123b8c6669ea32923fa626b27de5

quantum/common/test_lib.py
run_tests.py
run_tests.sh
tools/pip-requires

index 2ccd681ce031b70ac6b831824388c5c080f6db32..a84eb77d340345c80dae47909fb0f9bfe2614dfd 100644 (file)
@@ -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)
index d73c0d518834f36a6266de4f26cfd3cb6461315f..34d56c502950222daec85c91722e8fce1daa07af 100644 (file)
@@ -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))
index 1f5a94b98dc7158fa50bf77c6268fa11350bbbe2..aee422a623ab610c1b27ace2f3d31635c4b420f8 100755 (executable)
@@ -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
index 31b66c77feb139a34cc08e5fbd5b6411a12cc458..4cdeae822fbbc9cb3229130f30c3fe01c55a066b 100644 (file)
@@ -1,6 +1,8 @@
+coverage
 eventlet>=0.9.12
 Routes>=1.12.3
 nose
+nosexcover
 Paste
 PasteDeploy
 pep8>=0.5.0