loading...

Using Codecov With Travis-CI (pytest-cov)

j0nimost profile image John Nyingi ・1 min read

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!!!

Posted on by:

j0nimost profile

John Nyingi

@j0nimost

I love learning new things, an explorer and a researcher at heart

Discussion

markdown guide