Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I integrate travis ci with codeclimate test coverage in Python?

I'm trying to make my Travis CI send test coverage data to Code Climate service, but documentation on Code Climate and Travis CI do not describe in detail how to do this using Python. Still its supported feature according Code Climate and Travis documentations. I've tried to find any working examples on this without luck and can't make it work on my own.

Code Climate documentation: Setting Up Test Coverage, Readme: codeclimate-test-reporter

Travis CI documentation: Using Code Climate with Travis CI

I've set the CODECLIMATE_REPO_TOKEN in Travis CI as described in this answer: https://stackoverflow.com/a/31281481/1754089

My .travis.yml file:

language: python
python:
  - 2.7
install:
  - pip install -r requirements.txt
  - pip install coverage
  - pip install codeclimate-test-reporter
#commands to run tests:
script:
  - python mytests.py
  - coverage run mytests.py
after_success:
  - codeclimate-test-reporter

as the after_success line is excecuted in Travis it gives me this in log-view:

/home/travis/build.sh: line 45: codeclimate-test_reporter: command not found
like image 989
Toni Nurmi Avatar asked Jun 26 '16 23:06

Toni Nurmi


People also ask

Which of the following analysis tool is used for code coverage in Travis CI?

Coveralls is a hosted analysis tool, providing statistics about your code coverage. Configuring your Travis CI build to send results to Coveralls always follows the same pattern: Add your repository to Coveralls.

What is Codeclimate diff coverage?

Code Climate allows users to enforce test coverage via our Github Pull Request Integration. The Enforce Diff Coverage option requires all new code in a Pull Request to meet a configurable minimum threshold of test coverage percentage. The default threshold is 50%.

What is the file format required for test coverage server?

cc-test-reporter format-coverage --prefix /usr/src/app.


1 Answers

Indeed it looks like at your end it's only an issue of a type as Peter mentioned in a comment. Your after_success should have codeclimate-test-reporter - it looks like you have it, but travis is reporting something else.

Now to why I opened a bounty and why it was actually just me being not understanding how codeclimate_test_reporter works. I wanted to report my coverage from py.test. codeclimate_test_reporter has a pretty readme on GitHub showing how to create a coverage report. However from their example, it looks like providing codeclimate-test-reporter as an argument to --cov would automatically send a report to codeclimate. That is not the case

Using py.test, what you want to do is:

script:
- py.test --cov=YourModuleYouWantToCover test_folder
- codeclimate-test-reporter --file .coverage

Magic happened, for the first time, I have a coverage report on codeclimate!

I submitted a pull request to codeclimate-test-reporter to update their readme and it has been merged, so hopefully less confusion for future people!

like image 198
iScrE4m Avatar answered Nov 15 '22 03:11

iScrE4m