From fbc8d14bec58035601b2bfd571c49993c9f907dc Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Sat, 18 Feb 2017 21:17:25 +0100 Subject: Configure pytest to run tests and coverage --- .coveragerc | 15 ++++++++++++++- conftest.py | 6 ++++++ setup.cfg | 19 +++++++++++++++++++ test-requirements.txt | 1 + tox.ini | 2 ++ 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 conftest.py diff --git a/.coveragerc b/.coveragerc index e1d918755..2c3199a3e 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,5 +1,18 @@ [run] -omit= +branch = True +omit = */lib/python*/site-packages/* */lib/python*/* /usr/* + setup.py + # TODO(rhcarvalho): this is used to ignore test files from coverage report. + # We can make this less generic when we stick with a single test pattern in + # the repo. + test_*.py + *_tests.py + +[report] +fail_under = 25 + +[html] +directory = cover diff --git a/conftest.py b/conftest.py new file mode 100644 index 000000000..ad03fab29 --- /dev/null +++ b/conftest.py @@ -0,0 +1,6 @@ +"""pytest configuration""" + + +def pytest_ignore_collect(path): + """Hook to ignore symlink files and directories.""" + return path.islink() diff --git a/setup.cfg b/setup.cfg index 757d3ddea..c8f1f9b87 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,3 +28,22 @@ lint_disable=fixme,locally-disabled,file-ignored,duplicate-code exclude=.tox/*,utils/*,inventory/* max_line_length = 120 ignore = E501,T003 + +[tool:pytest] +norecursedirs = + .* + __pycache__ + cover + docs + # utils have its own config + utils +python_files = + # TODO(rhcarvalho): rename test files to follow a single pattern. "test*.py" + # is Python unittest's default, while pytest discovers both "test_*.py" and + # "*_test.py" by default. + test_*.py + *_tests.py +addopts = + --cov=. + --cov-report=term + --cov-report=html diff --git a/test-requirements.txt b/test-requirements.txt index c3d0d9387..c4b54fabe 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -11,3 +11,4 @@ nose coverage mock pytest +pytest-cov diff --git a/tox.ini b/tox.ini index 4d3594023..ae781a04c 100644 --- a/tox.ini +++ b/tox.ini @@ -17,3 +17,5 @@ commands = yamllint: python setup.py yamllint unit: nosetests generate_validation: python setup.py generate_validation + + -- cgit v1.2.3