leverage tox to facilitate the development 69/29269/3
authorSerenaFeng <feng.xiaowei@zte.com.cn>
Thu, 23 Feb 2017 07:14:12 +0000 (15:14 +0800)
committerAric Gardner <agardner@linuxfoundation.org>
Fri, 24 Feb 2017 21:56:48 +0000 (21:56 +0000)
Before submitting a patch, we need to execute flake8, unittest,
open coverage report, now with the help of tox any pytest,
we can process them all with only one command.

pytest is choosen here is because of its useful assert showcase,
and powerful properties and healthy ecosystem(plugins of mock etc)

Change-Id: I7ee89da370da08cc2bc70f7d3b1e2741d7d2e1e8
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
.gitignore
utils/test/testapi/.coveragerc [new file with mode: 0644]
utils/test/testapi/test-requirements.txt [new file with mode: 0644]
utils/test/testapi/tox.ini [new file with mode: 0644]

index 918e321..0aa7b8c 100644 (file)
@@ -33,3 +33,5 @@ cover/
 coverage.xml
 nosetests.xml
 testapi_venv/
+.cache
+.tox
diff --git a/utils/test/testapi/.coveragerc b/utils/test/testapi/.coveragerc
new file mode 100644 (file)
index 0000000..23fb97f
--- /dev/null
@@ -0,0 +1,27 @@
+# .coveragerc to control coverage.py
+
+[run]
+branch = True
+source =
+    opnfv_testapi
+
+[report]
+# Regexes for lines to exclude from consideration
+exclude_lines =
+       # Have to re-enable the standard pragma
+       pragma: no cover
+
+       # Don't complain about missing debug-only code:
+       def __repr__
+       if self\.debug
+
+       # Don't complain if tests don't hit defensive assertion code:
+       raise AssertionError
+       raise NotImplementedError
+
+       # Don't complain if non-runnable code isn't run:
+       if 0:
+       if __name__ == .__main__.:
+
+ignore_errors = True
+
diff --git a/utils/test/testapi/test-requirements.txt b/utils/test/testapi/test-requirements.txt
new file mode 100644 (file)
index 0000000..8933319
--- /dev/null
@@ -0,0 +1,10 @@
+# The order of packages is significant, because pip processes them in the order
+# of appearance. Changing the order has an impact on the overall integration
+# process, which may cause wedges in the gate later.
+
+tox
+pytest
+pytest-cov
+coverage
+pykwalify
+pip_check_reqs
diff --git a/utils/test/testapi/tox.ini b/utils/test/testapi/tox.ini
new file mode 100644 (file)
index 0000000..81c9dfa
--- /dev/null
@@ -0,0 +1,41 @@
+# Tox (http://tox.testrun.org/) is a tool for running tests
+# in multiple virtualenvs. This configuration file will run the
+# test suite on all supported python versions. To use it, "pip install tox"
+# and then run "tox" from this directory.
+
+[tox]
+envlist = py27,pep8
+skipsdist = True
+sitepackages = True
+
+[testenv]
+usedevelop = True
+install_command = pip install -U {opts} {packages}
+deps =
+  -rrequirements.txt
+  -rtest-requirements.txt
+commands=
+  py.test \
+    --basetemp={envtmpdir} \
+    --cov \
+    {posargs}
+setenv=
+  HOME = {envtmpdir}
+  PYTHONPATH = {toxinidir}
+
+[testenv:pep8]
+deps = flake8
+commands = flake8 {toxinidir}
+
+[flake8]
+# H803 skipped on purpose per list discussion.
+# E123, E125 skipped as they are invalid PEP-8.
+
+show-source = True
+ignore = E123,E125,H803,E501
+builtins = _
+exclude = build,dist,doc,legacy,.eggs,.git,.tox,.venv,testapi_venv,venv
+
+[pytest]
+testpaths = opnfv_testapi/tests
+python_functions = test_*