DEV Community

John Nyingi
John Nyingi

Posted on

Using Codecov With Travis-CI (pytest-cov)

codecov-travis-pytest

Continuous Integration has brought about so much ease in ensuring quality code is pushed. Making developer lives easier, but it doesn't end there, testing is just a part of bigger picture. We also need to capture the test coverage, we want to assess the quality of our code by ensuring our tests meet the minimum threshold. For this we turn to pytest-cov.
Since we have Travis-CI already set up for our python project, let's add CodeCov to ensure we generate coverage reports from .travis.yml. To connect Github to Codecov is as easy as signing up with our Github account.

We can now proceed to our local machine and install pytest-cov, just by running pip install pytest-cov pytest then add codecov tool pip install codecov.
Generate a new requirements file, simply run pip freeze > requirements.txt

Afterwards, we open your .travis.yml file and add

   install:
    - pip install -r requirements.txt

   script:
    - py.test  --cov-report term --cov=app/test/

   env:
    - CODECOV_TOKEN=<token>#IF ONLY YOU HAVE A PRIVATE REPOSITORY

   after_success:
    - codecov

Just before you push everything in your root(app) directory run this
py.test --cov-report term --cov=app/test/, if successful you should see a new .coverage file. Add all of them to your git repository then PUSH. DONE!!!

Top comments (2)

Collapse
 
seokjeon profile image
Se-ok Jeon

Thx for this! This is really what I wanted. Helped A LOT.
Can I translate in Korean this article? If you don't mind, I wanna share this awesome information in Korean. Surely, There will be a link directing to this original one.

Collapse
 
j0nimost profile image
John Nyingi

Sure, go ahead and translate it.