From 2329b9227f27d28140907deeb952f8b04e7db253 Mon Sep 17 00:00:00 2001 From: beierl Date: Fri, 12 Jul 2019 11:55:36 -0400 Subject: [PATCH] Adds unit test coverage Adds the coverage and stestr modules to tox so that unit test code coverage reports can be generated. Change-Id: If67b31be5996de95e60ad73f63124e181ec955b5 Signed-off-by: beierl --- .gitignore | 4 +++- .stestr.conf | 3 +++ test-requirements.txt | 2 ++ tox.ini | 33 +++++++++++++++++++++++++-------- 4 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 .stestr.conf diff --git a/.gitignore b/.gitignore index d12e438..2b24c35 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,8 @@ pip-log.txt # Unit test / coverage reports .coverage +cover +.stestr .tox nosetests.xml .testrepository @@ -79,4 +81,4 @@ __pycache__/ *.db deb_dist -*.tar.gz \ No newline at end of file +*.tar.gz diff --git a/.stestr.conf b/.stestr.conf new file mode 100644 index 0000000..ae39f6f --- /dev/null +++ b/.stestr.conf @@ -0,0 +1,3 @@ +[DEFAULT] +test_path=${TESTS_DIR:-./osm_mon/tests/unit/} +top_dir=./ diff --git a/test-requirements.txt b/test-requirements.txt index c67a4b1..5741c91 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -22,3 +22,5 @@ flake8<3.0 mock requests-mock +coverage==4.5.3 +stestr>=1.0.0 diff --git a/tox.ini b/tox.ini index 3a360af..03f2d27 100644 --- a/tox.ini +++ b/tox.ini @@ -25,18 +25,36 @@ # test suite on all supported python versions. To use it, "pip install tox" # and then run "tox" from this directory. [tox] -envlist = py3, flake8, pylint -toxworkdir={homedir}/.tox +envlist = py3, flake8, pylint, cover + [testenv] -basepythons = python3 -commands=python3 -m unittest discover -v -install_command = python3 -m pip install -r requirements.txt -U {opts} {packages} -deps = -r{toxinidir}/test-requirements.txt +usedevelop = True +install_command = pip install -U {opts} {packages} +setenv = VIRTUAL_ENV={envdir} + PYTHONDONTWRITEBYTECODE = 1 + TESTS_DIR=./osm_mon/tests/unit/ +deps = -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt +commands = + coverage erase + +[testenv:cover] +basepython = python3 +setenv = VIRTUAL_ENV={envdir} + PYTHON=coverage run --source osm_mon --omit='*tests*' --parallel-mode +commands = + coverage erase + stestr run {posargs} + coverage combine + coverage report --omit='*tests*' + coverage html -d ./cover --omit='*tests*' + coverage xml -o ./cover/coverage.xml --omit='*tests*' [testenv:pylint] basepython = python3 deps = pylint + -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt commands = pylint -E osm_mon @@ -44,6 +62,7 @@ commands = [testenv:flake8] basepython = python3 deps = flake8 + -r{toxinidir}/requirements.txt commands = flake8 osm_mon @@ -60,5 +79,3 @@ show-source = True ignore = E123,E125,E241 builtins = _ exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,devops_stages/*,.rst - - -- 2.17.1