|
| 1 | +# [Codecov](https://codecov.io) Python Example |
| 2 | + |
| 3 | +## Guide |
| 4 | + |
| 5 | +### Travis Setup |
| 6 | + |
| 7 | +Add the following to your `.travis.yml`: |
| 8 | +```yml |
| 9 | +language: |
| 10 | + python |
| 11 | +after_success: |
| 12 | + - bash <(curl -s https://codecov.io/bash) |
| 13 | +``` |
| 14 | +
|
| 15 | +### Produce Coverage Reports |
| 16 | +`coverage.py <https://bitbucket.org/ned/coveragepy>`_ is required to collect coverage metrics. |
| 17 | + |
| 18 | +Below are some examples on how to include coverage tracking during your tests. Codecov will call `coveragexml -i` automatically to generate the coverage xml output, which will be archived and processed server side. |
| 19 | + |
| 20 | +You may need to configure a ``.coveragerc`` file. Learn more `here <http://coverage.readthedocs.org/en/latest/config.html>`_. Start with this `generic .coveragerc <https://gist.github.com/codecov-io/bf15bde2c7db1a011b6e>`_ for example. |
| 21 | + |
| 22 | +We highly suggest adding `source` to your ``.coveragerc`` which solves a number of issues collecting coverage. |
| 23 | + |
| 24 | +```ini |
| 25 | +[run] |
| 26 | +source=your_package_name |
| 27 | +``` |
| 28 | +#### unittests |
| 29 | +``` |
| 30 | +pip install coverage |
| 31 | +coverage run tests.py |
| 32 | +``` |
| 33 | +#### pytest |
| 34 | +``` |
| 35 | +ptest --cov=./ |
| 36 | +``` |
| 37 | +#### nosetests |
| 38 | +``` |
| 39 | +nosetest --with-coverage |
| 40 | +``` |
| 41 | +See the `Offical Nose coverage docs <http://nose.readthedocs.org/en/latest/plugins/cover.html>`_ for more information. |
| 42 | +
|
| 43 | +### Testing with ``tox`` |
| 44 | +
|
| 45 | +Codecov can be run from inside your ``tox.ini`` please make sure you pass all the necessary environment variables through: |
| 46 | +```ini |
| 47 | +[testenv] |
| 48 | +passenv = CI TRAVIS TRAVIS_* |
| 49 | +deps = codecov |
| 50 | +commands = codecov |
| 51 | +``` |
| 52 | + |
| 53 | +### FAQ |
| 54 | +- Q: What's the difference between the codecov-bash and codecov-python uploader?<br/>A: As far as python is concerned, *nothing*. You may choose to use either uploader. Codecov recommends **using the bash uploader when possible** as it supports more unique repository setups. Learn more at `codecov/codecov-bash <https://github.com/codecov/codecov-bash>`_ and `codecov/codecov-python <https://github.com/codecov/codecov-python>`_. |
| 55 | +- Q: Why am I seeing `No data to report`?<br/>A: This output is written by running the command ``coverage xml`` and states that there were no ``.coverage`` files found. |
| 56 | + 1. Make sure coverage is enabled. See Enabling Coverage |
| 57 | + 2. You may need to run `coverage combine` before running Codecov. |
| 58 | + 3. Using Docker? Please follow this step: `Testing with Docker: Codecov Inside Docker <https://github.com/codecov/support/wiki/Testing-with-Docker#codecov-inside-docker>`_. |
| 59 | +- Q: Can I upload my ``.coverage`` files?<br/> A: **No**, these files contain coverage data but are not properly mapped back to the source code. We rely on ``coveragepy`` to handle this by calling ``coverage xml`` in the uploader. |
| 60 | + |
| 61 | +## Caveats |
| 62 | +### Private Repo |
| 63 | +Repository tokens are required for (a) all private repos, (b) public repos not using Travis-CI, CircleCI or AppVeyor. Find your repository token at Codecov and provide via appending `-t <your upload token>` to you where you upload reports. |
| 64 | + |
| 65 | +### Cobertura Reports |
| 66 | +Cobertura reports can expire - Codecov will reject reports that are older than 12 hours. The logs contain details if a report expired. |
| 67 | + |
| 68 | +## Links |
| 69 | +- [Community Boards](https://community.codecov.io) |
| 70 | +- [Support](https://codecov.io/support) |
| 71 | +- [Documentation](https://docs.codecov.io) |
| 72 | + |
0 commit comments