├── .circleci └── config.yml ├── .github ├── dependabot.yml └── workflows │ ├── ci.yml │ └── enforce-license-compliance.yml ├── .gitignore ├── LICENSE.md ├── README.md ├── app ├── __init__.py ├── calculator.py └── test_calculator.py ├── bitrise.yml ├── codecov.yml └── requirements.txt /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | orbs: 3 | codecov: codecov/codecov@4 4 | 5 | jobs: 6 | build: 7 | docker: 8 | - image: cimg/python:3.10 9 | steps: 10 | - checkout 11 | - run: 12 | name: Install dependencies 13 | command: pip install -r requirements.txt 14 | - run: 15 | name: Run tests and collect coverage 16 | command: pytest --cov app 17 | - codecov/upload 18 | 19 | workflow: 20 | version: 2.1 21 | build-test: 22 | jobs: 23 | - build 24 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: pip 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | open-pull-requests-limit: 10 8 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Workflow for Codecov example-python 2 | on: [push, pull_request] 3 | jobs: 4 | run: 5 | runs-on: ubuntu-latest 6 | permissions: 7 | id-token: write 8 | steps: 9 | - name: Checkout 10 | uses: actions/checkout@v4 11 | - name: Set up Python 3.10 12 | uses: actions/setup-python@v4 13 | with: 14 | python-version: '3.10' 15 | - name: Install dependencies 16 | run: pip install -r requirements.txt 17 | - name: Run tests and collect coverage 18 | run: pytest --cov app 19 | - name: Upload coverage to Codecov (arg token) 20 | uses: codecov/codecov-action@main 21 | with: 22 | fail_ci_if_error: true 23 | token: ${{ secrets.CODECOV_TOKEN }} 24 | verbose: true 25 | - name: Upload coverage to Codecov (env token) 26 | uses: codecov/codecov-action@main 27 | with: 28 | fail_ci_if_error: true 29 | verbose: true 30 | env: 31 | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} 32 | - name: Upload coverage to Codecov (no token) 33 | uses: codecov/codecov-action@main 34 | with: 35 | fail_ci_if_error: true 36 | verbose: true 37 | - name: Upload coverage to Codecov (oidc) 38 | uses: codecov/codecov-action@main 39 | with: 40 | fail_ci_if_error: true 41 | use_oidc: true 42 | verbose: true 43 | -------------------------------------------------------------------------------- /.github/workflows/enforce-license-compliance.yml: -------------------------------------------------------------------------------- 1 | name: Enforce License Compliance 2 | 3 | on: 4 | pull_request: 5 | branches: [main, master] 6 | 7 | jobs: 8 | enforce-license-compliance: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: 'Enforce License Compliance' 12 | uses: getsentry/action-enforce-license-compliance@57ba820387a1a9315a46115ee276b2968da51f3d # main 13 | with: 14 | fossa_api_key: ${{ secrets.FOSSA_API_KEY }} 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ 2 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Codecov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [Codecov](https://codecov.io) Python Example 2 | [![codecov](https://codecov.io/github/codecov/example-python/branch/main/graph/badge.svg?token=tkq655ROg3)](https://app.codecov.io/github/codecov/example-python) 3 | [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-python.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-python?ref=badge_shield) 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. 6 | 7 | For more information, please see the links below. 8 | 9 | ## Links 10 | - [Quick Start](https://docs.codecov.com/docs/quick-start) 11 | - [GitHub Tutorial](https://docs.codecov.com/docs/github-tutorial) 12 | - [Community Boards](https://community.codecov.io) 13 | - [Support](https://codecov.io/support) 14 | - [Documentation](https://docs.codecov.io) 15 | 16 | 17 | ## License 18 | [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-python.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-python?ref=badge_large) 19 | -------------------------------------------------------------------------------- /app/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codecov/example-python/4fbb7d49e9af169da717a9907c74f6bdc7c235cb/app/__init__.py -------------------------------------------------------------------------------- /app/calculator.py: -------------------------------------------------------------------------------- 1 | class Calculator: 2 | 3 | def add(x, y): 4 | return x + y 5 | 6 | def subtract(x, y): 7 | return x - y 8 | 9 | def multiply(x, y): 10 | return x * y 11 | 12 | def divide(x, y): 13 | if y == 0: 14 | return 'Cannot divide by 0' 15 | return x * 1.0 / y 16 | 17 | -------------------------------------------------------------------------------- /app/test_calculator.py: -------------------------------------------------------------------------------- 1 | from .calculator import Calculator 2 | 3 | 4 | def test_add(): 5 | assert Calculator.add(1, 2) == 3.0 6 | assert Calculator.add(1.0, 2.0) == 3.0 7 | assert Calculator.add(0, 2.0) == 2.0 8 | assert Calculator.add(2.0, 0) == 2.0 9 | assert Calculator.add(-4, 2.0) == -2.0 10 | 11 | def test_subtract(): 12 | assert Calculator.subtract(1, 2) == -1.0 13 | assert Calculator.subtract(2, 1) == 1.0 14 | assert Calculator.subtract(1.0, 2.0) == -1.0 15 | assert Calculator.subtract(0, 2.0) == -2.0 16 | assert Calculator.subtract(2.0, 0.0) == 2.0 17 | assert Calculator.subtract(-4, 2.0) == -6.0 18 | 19 | def test_multiply(): 20 | assert Calculator.multiply(1, 2) == 2.0 21 | assert Calculator.multiply(1.0, 2.0) == 2.0 22 | assert Calculator.multiply(0, 2.0) == 0.0 23 | assert Calculator.multiply(2.0, 0.0) == 0.0 24 | assert Calculator.multiply(-4, 2.0) == -8.0 25 | 26 | def test_divide(): 27 | # assert Calculator.divide(1, 2) == 0.5 28 | assert Calculator.divide(1.0, 2.0) == 0.5 29 | assert Calculator.divide(0, 2.0) == 0 30 | assert Calculator.divide(-4, 2.0) == -2.0 31 | # assert Calculator.divide(2.0, 0.0) == 'Cannot divide by 0' 32 | -------------------------------------------------------------------------------- /bitrise.yml: -------------------------------------------------------------------------------- 1 | format_version: "13" 2 | default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git 3 | project_type: other 4 | workflows: 5 | primary: 6 | steps: 7 | - activate-ssh-key@4: 8 | run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}' 9 | - git-clone@8: {} 10 | - script@1: 11 | inputs: 12 | - script_file_path: null 13 | - content: | 14 | #!/usr/bin/env bash 15 | set -e 16 | set -o pipefail 17 | set -x # debug log 18 | 19 | pip3 install -r requirements.txt 20 | pytest --cov app 21 | - codecov@3: 22 | inputs: 23 | - OS: macos 24 | - CODECOV_TOKEN: $CODECOV_TOKEN 25 | - deploy-to-bitrise-io@2: {} 26 | meta: 27 | bitrise.io: 28 | stack: osx-xcode-14.3.x-ventura 29 | machine_type_id: g2-m1.4core 30 | trigger_map: 31 | - push_branch: main 32 | workflow: primary 33 | - pull_request_source_branch: '*' 34 | workflow: primary 35 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | flag_management: 2 | individual_flags: 3 | - name: smart-tests 4 | carryforward: true 5 | carryforward_mode: "labels" 6 | statuses: 7 | - type: "project" 8 | - type: "patch" 9 | 10 | cli: 11 | plugins: 12 | pycoverage: 13 | report_type: "json" 14 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | attrs==25.3.0 2 | coverage==7.8.1 3 | iniconfig==2.1.0 4 | packaging==25.0 5 | pluggy==1.6.0 6 | py==1.11.0 7 | pyparsing==3.2.3 8 | pytest==8.3.5 9 | pytest-cov==6.1.0 10 | tomli==2.2.1 11 | --------------------------------------------------------------------------------