|
1 | 1 | # [Codecov](https://codecov.io) Python Example |
| 2 | +[](https://codecov.io/github/codecov/example-python) |
2 | 3 | [](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-python?ref=badge_shield) |
3 | 4 |
|
| 5 | +This example repository shows how Codecov can be integrated with a simple python project. It uses **GitHub Actions** and **CircleCI** as CI/CD providers and **coverage** as the coverage provider. |
4 | 6 |
|
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 | | -coverage xml |
42 | | -``` |
43 | | -#### pytest |
44 | | -``` |
45 | | -pip install pytest-cov |
46 | | -pytest --cov=./ --cov-report=xml |
47 | | -``` |
48 | | -#### nosetests |
49 | | -``` |
50 | | -nosetest --with-coverage |
51 | | -``` |
52 | | -See the [Offical Nose coverage docs](http://nose.readthedocs.org/en/latest/plugins/cover.html) for more information. |
53 | | -
|
54 | | -### Testing with ``tox`` |
55 | | -
|
56 | | -Codecov can be run from inside your `tox.ini` please make sure you pass all the necessary environment variables through: |
57 | | -```ini |
58 | | -[testenv] |
59 | | -passenv = CI TRAVIS TRAVIS_* |
60 | | -deps = codecov |
61 | | -commands = codecov |
62 | | -``` |
63 | | - |
64 | | -### FAQ |
65 | | -- Q: What's the difference between the codecov-bash and codecov-python uploader? |
66 | | - 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). |
67 | | -- Q: Why am I seeing `No data to report`? |
68 | | - A: This output is written by running the command `coverage xml` and states that there were no `.coverage` files found. |
69 | | - 1. Make sure coverage is enabled. See Enabling Coverage |
70 | | - 2. You may need to run `coverage combine` before running Codecov. |
71 | | - 3. Using Docker? Please follow this step: [Testing with Docker: Codecov Inside Docker](https://docs.codecov.io/docs/testing-with-docker#codecov-inside-docker). |
72 | | -- Q: Can I upload my `.coverage` files? |
73 | | - 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. |
74 | | - |
75 | | -## Caveats |
76 | | -### Private Repo |
77 | | -Repository tokens are required for (a) all private repos, (b) public repos not using the GitHub Actions, Travis CI, CircleCI or AppVeyor. |
78 | | - |
79 | | -Find your repository token at Codecov and provide via appending `-t <your upload token>` to you where you upload reports. |
80 | | - |
81 | | -### Cobertura Reports |
82 | | -Cobertura reports can expire - Codecov will reject reports that are older than 12 hours. The logs contain details if a report expired. |
| 7 | +For more information, please see the links below. |
83 | 8 |
|
84 | 9 | ## Links |
| 10 | +- [Quick Start](https://docs.codecov.com/docs/quick-start) |
| 11 | +- [GitHub Tutorial](https://docs.codecov.com/docs/github-tutorial) |
85 | 12 | - [Community Boards](https://community.codecov.io) |
86 | 13 | - [Support](https://codecov.io/support) |
87 | 14 | - [Documentation](https://docs.codecov.io) |
88 | 15 |
|
89 | 16 |
|
90 | | - |
91 | 17 | ## License |
92 | 18 | [](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-python?ref=badge_large) |
0 commit comments