Integrating coveralls with travis in a python project- 2 mins
This post is about setting up coveralls and travis in a Python project.
Greb is a dictionary cli, written in Python which uses Travis to check whether the test cases are running fine or not. Travis as the wiki says is a continuous integration service which is used to build and test software projects hosted on Github.
Config for travis lives in a file called
.travis.yml which should be present at the root directory of the project. When any commit is pushed or a pull request is created, a webhook is triggered, which initiates the travis and it then checks the build process.
Initially, greb had only a travis integration, which looked something like
language: python python: - "3.4" - "3.3" - "2.7" install: - "pip install ." - "pip install flake8" - "pip install ." script: - "python -m test.test_greb" - "flake8 greb" - "flake8 test"
The file is self-explanatory, except the script part. Here I am using unit testing hence the line
python -m test.test_greb
Now I wanted to integrate coveralls.io in greb. The integration is very simple. Here are the steps
Set environment variable
COVERALLS_REPO_TOKENin settings on Travis for the project. The value for this variable can be found from Coveralls website at the bottom right corner.
.travis.ymlper section as follows:
pip install coverallsin install section
python -m test.test_grebto
coverage run --source=greb -m test.test_grebin script
- Add a new section namely after_script and add
coverage run can be considered as python executable, hence passing
-m test.test_greb. It generates a
.coveragefile which gets pushed to coveralls.io, where it is presented in a nicely formatted way.
.travis.yml will look something like
language: python python: - "3.4" - "3.3" - "2.7" install: - "pip install ." - "pip install flake8" - "pip install coveralls" script: - "flake8 greb" - "flake8 test" - "coverage run --source=greb -m test.test_greb" after_script: - coveralls