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.
For example:
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.
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
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.