|
1 | | -Python Example |
2 | | -======= |
3 | | -| [https://codecov.io/][1] | [@codecov][2] | [hello@codecov.io][3] | |
4 | | -| ------------------------ | ------------- | --------------------- | |
5 | | - |
6 | | -> Example of how to integrate with [Codecov.io][1] for your **awesome** Python project! |
7 | | -
|
8 | | -## See this repo's [Coverage Reports][4] |
9 | | - |
| 1 | +[Codecov][1] Python Example |
| 2 | +=========================== |
10 | 3 |
|
11 | 4 | ## Usage |
12 | 5 |
|
13 | 6 | ```sh |
| 7 | +# 1) install codecov |
14 | 8 | pip install codecov |
15 | | -codecov --token=<repo token> |
16 | | -``` |
17 | | - |
18 | | -## Using `tox`? |
19 | | -Codecov can be ran from inside your `tox.ini` please make sure you pass all the necessary environment variables through: |
20 | | - |
21 | | -``` |
22 | | -[testenv] |
23 | | -passenv = CI TRAVIS TRAVIS_* |
24 | | -deps = codecov>=1.4.0 |
25 | | -commands = codecov -e TOXENV |
26 | | -``` |
27 | | -> See all the environment variable for other CI providers [here](https://github.com/codecov/codecov-python/blob/master/codecov/__init__.py#L260-L430). Note the `-e TOXENV` is used to distinquish builds in Codecov UI [example](https://codecov.io/gh/pyca/cryptography?ref=99c45f19be196cb45bf8de8ea105fcb4619ab504&build=7312.1). |
28 | | -
|
29 | | -## Private repositories |
30 | | -Please provide your private repository token (found at Codecov) to upload reports. |
31 | 9 |
|
32 | | -``` |
33 | | -export CODECOV_TOKEN=:token |
| 10 | +# 2) next call "codecov" at end of CI build |
| 11 | +# public repo using Travis, CircleCI or AppVeyor |
34 | 12 | codecov |
35 | | -# or |
36 | | -codecov -t :token |
37 | | -``` |
38 | | - |
39 | | -# Some example CI providers |
40 | | - |
41 | | -### [](https://travis-ci.org) Travis CI |
42 | | -> Append to your `.travis.yml` |
43 | | -
|
44 | | -```yml |
45 | | -install: |
46 | | - pip install codecov |
47 | | -after_success: |
48 | | - codecov |
49 | | -``` |
50 | | -
|
51 | | -> Note: No need to include a repository token for **public** repos on Travis |
52 | | -
|
53 | | -
|
54 | | -### [](https://circleci.com/) [Circle CI](https://circleci.com/). |
55 | | -> Append to your `circle.yml` file |
56 | 13 |
|
57 | | -```yml |
58 | | -test: |
59 | | - post: |
60 | | - - pip install codecov && codecov |
| 14 | +# all other CI and priveta repositories |
| 15 | +codecov --token=<repo token> |
61 | 16 | ``` |
62 | | -> Note: No need to include a repository token for **public** repos on CircleCI |
63 | | - |
64 | 17 |
|
65 | 18 | ## How to generate coverage reports |
66 | 19 |
|
67 | 20 | The use of [coverage.py](https://bitbucket.org/ned/coveragepy) is required. Below are some examples on how to include coverage tracking during your tests. Codecov will call `coverage xml -i` automatically to generate the coverage xml output, which will be archived and processed server side. |
68 | 21 |
|
69 | 22 | > 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. |
70 | 23 |
|
71 | | -#### Default |
| 24 | +#### unittests |
72 | 25 |
|
73 | 26 | ```py |
74 | 27 | pip install coverage |
75 | 28 | coverage run tests.py |
76 | 29 | ``` |
77 | 30 |
|
78 | | -#### Using pytest |
| 31 | +#### pytest |
79 | 32 |
|
80 | 33 | ```py |
81 | 34 | pip install pytest-cov |
82 | 35 | py.test --cov=./ |
83 | 36 | ``` |
84 | 37 |
|
85 | | -#### Using nosetests |
| 38 | +#### nosetests |
86 | 39 | > http://nose.readthedocs.org/en/latest/plugins/cover.html |
87 | 40 |
|
88 | 41 | ```py |
89 | 42 | nosetest --with-coverage |
90 | 43 | ``` |
91 | 44 |
|
92 | 45 |
|
| 46 | +## Testing with `tox` |
| 47 | + |
| 48 | +Codecov can be ran from inside your `tox.ini` please make sure you pass all the necessary environment variables through: |
| 49 | + |
| 50 | +``` |
| 51 | +[testenv] |
| 52 | +passenv = CI TRAVIS TRAVIS_* |
| 53 | +deps = codecov |
| 54 | +commands = codecov |
| 55 | +``` |
| 56 | +> See all the environment variable for other CI providers [here](https://github.com/codecov/codecov-bash/blob/master/env). |
| 57 | +
|
| 58 | + |
| 59 | +------- |
| 60 | + |
| 61 | +# Frequently Asked Questions |
| 62 | + |
| 63 | +####❔Whats the different between the codecov-bash and codecov-python uploader? |
| 64 | + |
| 65 | +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. |
| 66 | + |
| 67 | +Learn more at [codecov/codecov-bash](https://github.com/codecov/codecov-bash) and [codecov/codecov-python](https://github.com/codecov/codecov-python) |
| 68 | + |
| 69 | + |
| 70 | +####❔Why am I seeing `No data to report.` |
| 71 | +This output is written by running the command `coverage xml` and states that there were no `.coverage` files found. |
| 72 | + |
| 73 | +1. Make sure coverage is enabled. See [Enabling Coverage](#enabling-coverage) |
| 74 | +2. You may need to run `coverage combine` before running Codecov |
| 75 | +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) |
| 76 | + |
| 77 | +####❔Can I upload my `.coverage` files? |
| 78 | + |
| 79 | +**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. |
| 80 | + |
| 81 | + |
93 | 82 |
|
94 | 83 | [1]: https://codecov.io/ |
95 | 84 | [2]: https://twitter.com/codecov |
|
0 commit comments