|
1 | 1 | # [Codecov](https://codecov.io) Python Example |
2 | 2 | [](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-python?ref=badge_shield) |
3 | 3 |
|
4 | | - |
5 | | -## Guide |
6 | | - |
7 | | -### GitHub Actions |
8 | | -A minimal configuration might look like: |
9 | | - |
10 | | -```yml |
11 | | -steps: |
12 | | - # (Other steps go here) |
13 | | - - name: "Upload coverage to Codecov" |
14 | | - uses: codecov/codecov-action@v2 |
15 | | - with: |
16 | | - fail_ci_if_error: true |
17 | | - token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos |
18 | | -``` |
19 | | -
|
20 | | -See [codecov/codecov-action](https://github.com/codecov/codecov-action) for |
21 | | -more information, a [detailed example](https://github.com/codecov/codecov-action#example-workflowyml-with-codecov-action), |
22 | | -and other options. |
23 | | -
|
24 | | -### Produce Coverage Reports |
25 | | -[coverage.py](https://github.com/nedbat/coveragepy) is required to collect coverage metrics. |
26 | | -
|
27 | | -Below are some examples on how to include coverage tracking during your tests. You will need to call `coverage xml` to generate the coverage xml output, which will be archived and processed server side. |
28 | | - |
29 | | -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. |
30 | | - |
31 | | -We highly suggest adding `source` to your `.coveragerc` which solves a number of issues collecting coverage. |
32 | | - |
33 | | -```ini |
34 | | -[run] |
35 | | -source=your_package_name |
36 | | -``` |
37 | | -#### unittests |
38 | | -``` |
39 | | -pip install coverage |
40 | | -coverage run tests.py |
41 | | -``` |
42 | | -#### pytest |
43 | | -``` |
44 | | -pip install pytest-cov |
45 | | -pytest --cov=./ |
46 | | -``` |
47 | | -#### nosetests |
48 | | -``` |
49 | | -nosetest --with-coverage |
50 | | -``` |
51 | | -See the [Offical Nose coverage docs](http://nose.readthedocs.org/en/latest/plugins/cover.html) for more information. |
52 | | -
|
53 | | -### Testing with ``tox`` |
54 | | -
|
55 | | -Codecov can be run from inside your `tox.ini` please make sure you pass all the necessary environment variables through: |
56 | | -```ini |
57 | | -[testenv] |
58 | | -passenv = CI TRAVIS TRAVIS_* |
59 | | -deps = codecov |
60 | | -commands = codecov |
61 | | -``` |
62 | | - |
63 | | -### FAQ |
64 | | -- Q: What's the difference between the codecov-bash and codecov-python uploader? |
65 | | - 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). |
66 | | -- Q: Why am I seeing `No data to report`? |
67 | | - A: This output is written by running the command `coverage xml` and states that there were no `.coverage` files found. |
68 | | - 1. Make sure coverage is enabled. See Enabling Coverage |
69 | | - 2. You may need to run `coverage combine` before running Codecov. |
70 | | - 3. Using Docker? Please follow this step: [Testing with Docker: Codecov Inside Docker](https://docs.codecov.io/docs/testing-with-docker#codecov-inside-docker). |
71 | | -- Q: Can I upload my `.coverage` files? |
72 | | - 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. |
73 | | - |
74 | | -## Caveats |
75 | | -### Private Repo |
76 | | -Repository tokens are required for (a) all private repos, (b) public repos not using the GitHub Actions, Travis CI, CircleCI or AppVeyor. |
77 | | - |
78 | | -Find your repository token at Codecov and provide via appending `-t <your upload token>` to you where you upload reports. |
79 | | - |
80 | | -### Cobertura Reports |
81 | | -Cobertura reports can expire - Codecov will reject reports that are older than 12 hours. The logs contain details if a report expired. |
| 4 | +This example repository shows how Codecov can be integrated with a simple python project. For more information, please see the links below. |
82 | 5 |
|
83 | 6 | ## Links |
| 7 | +- [Quick Start](https://docs.codecov.com/docs/quick-start) |
| 8 | +- [GitHub Tutorial](https://docs.codecov.com/docs/github-tutorial) |
84 | 9 | - [Community Boards](https://community.codecov.io) |
85 | 10 | - [Support](https://codecov.io/support) |
86 | 11 | - [Documentation](https://docs.codecov.io) |
87 | 12 |
|
88 | 13 |
|
89 | | - |
90 | 14 | ## License |
91 | 15 | [](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-python?ref=badge_large) |
0 commit comments