How To Use Coverage.py With Unittest
This is adapted from: * http://nedbatchelder.com/code/coverage/
First, install Coverage.py:
pip install coverage
Run your test suite, but replace python blah blah with coverage blah blah and specify a source directory.
coverage run --source cookiecutter setup.py test
Ideally your tests should be outside of your source directory, so that you don't have to configure excludes or package them. It's much neater that way.
Print Coverage Reports
To print a quick command line report, maximize your command prompt and type:
coverage report -m
To print a fancier HTML report:
coverage html open html_cov/index.html
Set Up Coveralls
Sign up for Coveralls.io with your GitHub account. Click [Add Repo] and add the repo for which you want a badge.
Here you'll use coveralls-python.
Add this to .travis.yml in the corresponding spots:
install: - pip install coveralls # change from 'script: python setup.py test' to this script: coverage run --source cookiecutter setup.py test after_success: coveralls
Then when you push, after Travis finishes building, check your Coveralls account for the results.