Set up test coverage tool
Introduce two new commands for tox to measure test coverage and
generate reports using coverage.py
Issue: HIC-162
Change-Id: Iaaf77d981a335e1befcfb59e2294250ed22e0e2b
diff --git a/.coveragerc b/.coveragerc
new file mode 100644
index 0000000..36d6325
--- /dev/null
+++ b/.coveragerc
@@ -0,0 +1,28 @@
+[run]
+branch = True
+omit =
+ */migrations/*
+ */tests.py
+ .tox/*
+ .venv/*
+ manage.py
+
+[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__.:
+
+show_missing = True
\ No newline at end of file
diff --git a/README.md b/README.md
index 6adeaa5..e2559f3 100644
--- a/README.md
+++ b/README.md
@@ -157,10 +157,22 @@
(hiccupenv) $ pip install -r requirements-dev.txt
+#### Testing
+
Simply run `tox` to test your changes in the supported environments:
(hiccupenv) $ tox
+To get an overview of the test coverage run:
+
+ (hiccupenv) $ tox -e coverage
+
+To generate HTML coverage reports (saved to `htmlcov/`):
+
+ (hiccupenv) $ tox -e coverage-html
+
+#### Linters and Formatters
+
To run flake8 on only the diff with upstream:
(hiccupenv) $ git diff origin/master ./**/*py | flake8 --diff
diff --git a/requirements-dev.txt b/requirements-dev.txt
index 44621c2..206ba27 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -2,3 +2,4 @@
-rrequirements-dev-pylint.txt
tox
black
+coverage
\ No newline at end of file
diff --git a/tox.ini b/tox.ini
index fd93580..2130c1b 100644
--- a/tox.ini
+++ b/tox.ini
@@ -15,6 +15,23 @@
commands =
python manage.py test
+# Test coverage
+[testenv:coverage]
+deps =
+ {[testenv]deps}
+ coverage
+commands =
+ coverage run manage.py test
+ coverage report
+
+# Test coverage with html report
+[testenv:coverage-html]
+deps =
+ {[testenv:coverage]deps}
+commands =
+ {[testenv:coverage]commands}
+ coverage html
+
# Linters
[testenv:flake8]
deps =