Using Codecov With Travis-CI (pytest-cov)
John Nyingi

John Nyingi @j0nimost

About: Backend Dev

Location:
Nairobi, Kenya
Joined:
Feb 22, 2017

Using Codecov With Travis-CI (pytest-cov)

Publish Date: Jan 10 '19
9 2

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

Enter fullscreen mode Exit fullscreen mode

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

Comments 2 total

  • Se-ok Jeon
    Se-ok JeonOct 17, 2021

    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.

    • John Nyingi
      John NyingiOct 18, 2021

      Sure, go ahead and translate it.

Add comment