Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code coverage and integrate with Coveralls #2151

Closed
wants to merge 4 commits into from

Conversation

djkirkham
Copy link
Contributor

@djkirkham djkirkham commented Sep 22, 2016

Coveralls (http://coveralls.io) is a utility that can be integrated with a GitHub repository to display a code coverage percentage. It can be used with a variety of languages, but for Python it uses a utility called Coverage (https://coverage.readthedocs.io/en/coverage-4.2), which you can run in a terminal to produce text based reports.

This PR gets coverage/coveralls working on Iris via Travis. It's based on some initial work that @marqh did. Since I encountered a lot of obstacles trying to get it to work, and since I'm leaving for two weeks, I'll document the steps I needed to take.

Firstly, since the Iris tests run in parallel using Nose, it's necessary to set up Coverage to run on all the sub-processes. Coverage needs to be able run some set-up code for every process, and one way the docs suggest to do this is to add code to sitecustomize.py, which is run whenever the Python interpreter starts up. It's also necessary to set an environment variable COVERAGE_PROCESS_START with an absolute path to the Coverage configuration file to use. When calling the coverage command, it's necessary to specify both -p (parallel) and --concurrency=LIB, where LIB is replaced with the concurrency library used (multiprocessing for nose).

When running in parallel mode, Coverage produces a separate output file for each processor; these need to be combined using coverage combine before generating a report.

By default Coverage won't report on any libraries installed in the Python library directory. Additionally, for the web utility to be able to match the covered files to those in the GitHub repository, the files need to be run from where they are when Travis clones the repo. While it's not strictly necessary to be able to match the files, if they can't be matched one won't be able to inspect individual files at http://coveralls.io, which is quite useful. So, rather than running setup.py to install the files elsewhere and calling iris.tests.runner, I've changed the Travis script to run setup.py test.

I've added a new configuration to Travis that runs coverage with the default tests, rather than modifying the existing default configuration. This may or may not be necessary. I'm happy for it to be changed if not.

I've also restricted the version of cf_units to <1.1.1 (I tried making it =1.1.0, but it didn't work for some reason), because currently the Iris tests are failing with 1.1.2 (#2144 will fix them). Obviously the version should be unrestricted when merging.

Although the first commit shows @marqh as author, a lot of the changes in it were made by me. I only mention this so that people don't ask him questions about it expecting him to know the answer.

I've made sure certain files are omitted by Coverage when recording data (e.g. those in lib/iris/tests). Some additions could probably be made to these omissions.

@djkirkham
Copy link
Contributor Author

Currently coverage will only run if TEST_TARGET is default, even if you set COVERAGE=true for other targets.

@djkirkham djkirkham changed the title Add code coverage and integegrate with Coveralls Add code coverage and integrate with Coveralls Sep 22, 2016
@djkirkham
Copy link
Contributor Author

Annoyingly, since the code takes longer to run under coverage, it fails due to timeouts even more than it was before.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 69ad920 on djkirkham:coveralls into * on SciTools:master*.

@QuLogic
Copy link
Member

QuLogic commented Sep 22, 2016

All this setup stuff sounds pretty complicated. Is there a way we could enable the nose coverage plugin instead, which I'd hope takes care of all that for us?

@QuLogic
Copy link
Member

QuLogic commented Sep 22, 2016

By default Coverage won't report on any libraries installed in the Python library directory.

Adding something like /home/travis/virtualenv/python*/lib/python*/site-packages/iris/ to the sources should get that to work. You still need the coverage combine to flatten the paths as well.

@QuLogic QuLogic mentioned this pull request Oct 7, 2016
@QuLogic
Copy link
Member

QuLogic commented Oct 7, 2016

You might also want to try out codecov.io; it might be a bit smarter about file paths. It's also got some sort of browser extension that allows you to see code coverage directly on GitHub, though I've not used it.

@djkirkham
Copy link
Contributor Author

All this setup stuff sounds pretty complicated. Is there a way we could enable the nose coverage plugin instead, which I'd hope takes care of all that for us?

Initially I didn't go down that route because I didn't want to modify the Iris library code (Nose is called in lib/iris/tests/runner/_runner.py), but I now see that you can enable the behaviour by setting an environment variable, so maybe that's the way to go.

You might also want to try out codecov.io

That does look good, thanks!

I'm not able to work on this right now so if someone else wants to take over be my guest.

@pelson
Copy link
Member

pelson commented Oct 19, 2017

Closing for now. I'm 👍 on adding coverage, and happy for this PR to be re-opened if you can get this back up and running @djkirkham.

@pelson pelson closed this Oct 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants