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

2

8

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://mcmap.net/q/1471021/-why-won-39-t-travis-ci-run-the-codeclimate-script-for-my-node-app

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
Spatiotemporal answered 26/6, 2016 at 23:10 Comment(1)
According to your error message, you have a typo in your script. Note the underscore in codeclimate-test_reporter.Sakhuja
P
5

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!

Pathway answered 22/8, 2016 at 11:54 Comment(1)
Thank you for your time and efford!Spatiotemporal
T
0

The codeclimate python-test-reporter has since been deprecated. Updated way to handle test-report for python using travis-ci can be found at https://github.com/codeclimate/test-reporter/blob/master/examples/python_examples.md

Trouveur answered 23/12, 2019 at 19:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.