rhar
rhar

Reputation: 1

How to combine coverage.xml files for github action coverage report?

I wrote code related to a website in python. Below is my file structure,

├── app_layer
│   ├── src
│   └── tests
├── core
│   ├── src
│   └── tests
├── model
│   ├── src
│   └── tests
├── .github
│   ├── run-tests.yaml

How do i generate combined coverage report of all tests in app_layer, core and model ?

I wrote run-tests.yaml like-

name: Run Unit Tests

on: [pull_request]

env:
  ENV: test
  TEAM_SUFFIX: -mlp-stag
  VPC_SUFFIX: -stag
  CONFIG_SERVICE_MYSQL_DATABASE: main
  CONFIG_SERVICE_MYSQL_HOST: localhost:3306
  VAULT_SERVICE_MYSQL_USERNAME: ${{ secrets.LOCAL_DB_USER }}
  VAULT_SERVICE_MYSQL_PASSWORD: ${{ secrets.LOCAL_DB_PASSWORD }}
  GITHUB_TOKEN: ${{ secrets.COMMIT_ACCESS_TOKEN }}

jobs:
  run-tests:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v2
      with:
        fetch-depth: 0

    - name: Set up Python
      uses: actions/setup-python@v3
      with:
        python-version: "3.9"

    - name: Setup local mysql, elasticsearch and kafka
      run: |
        echo "Running setup.sh script"
        sh app_layer/tests/setup.sh
        echo "Setup complete"
        
        echo "Sleeping for 20 seconds"
        sleep 20
        
        echo "Running mysql setup"
        INSERT_QUERY="CREATE DATABASE IF NOT EXISTS main";
        mysql -u ${VAULT_SERVICE_MYSQL_USERNAME} -p${VAULT_SERVICE_MYSQL_PASSWORD} -h 127.0.0.1 -P 3306 <<< $INSERT_QUERY
        mysql -u ${VAULT_SERVICE_MYSQL_USERNAME} -p${VAULT_SERVICE_MYSQL_PASSWORD} main -h 127.0.0.1 -P 3306 < resources/db/mysql/migrations/20230627145332_CreateTables.sql
        echo "Mysql Setup complete"
                
        echo "Running elasticsearch setup"
        curl -X PUT "localhost:9200/computea_v2"
        echo "Elasticsearch setup complete"

    - name: Build Project
      run: |
        # Requirement Installation
        pip install -e app_layer/. --force-reinstall
        pip install mysql-connector-python~=8.0.33
        pip install PyYAML==6.0
        pip install shortuuid==1.0.11
        pip install python-dateutil==2.8.2
        pip install boto3~=1.34.54
        pip install loguru==0.7.2
        pip install mlp_commons@git+https://${GITHUB_TOKEN}:[email protected]/11/mlp-commons@feat/kafka
        pip install -e model/. --force-reinstall
        pip install -e script/. --force-reinstall
        pip install urllib3==1.26.6 --force-reinstall
        pip install pytest==8.0.1 --force-reinstall
        pip install pytest-cov==4.1.0 --force-reinstall

    - name: Run tests
      run: |
            LOG_FILE=compute.log pytest --junitxml=pytest.xml -v --ignore='tests/' --cov-report json --cov='app_layer/src' --cov='core/src' --cov='model/src' --cov-report "xml:coverage.xml" --cov-branch app_layer && 
            pytest --junitxml=pytest.xml -v --ignore='tests/' --cov-report json --cov='app_layer/src' --cov='core/src' --cov='model/src' --cov-report "xml:coverage.xml" --cov-branch core && 
            pytest --junitxml=pytest.xml -v --ignore='tests/' --cov-report json --cov='app_layer/src' --cov='core/src' --cov='model/src' --cov-report "xml:coverage.xml" --cov-branch model &&
            echo "Tests complete"

    - name: Pytest coverage comment
      if: always()
      uses: MishaKav/pytest-coverage-comment@main
      with:
        pytest-xml-coverage-path: ./coverage.xml
        junitxml-path: ./pytest.xml

    - name: Display coverage report
      uses: actions/upload-artifact@v3
      if: success() || failure()
      with:
        name: Coverage Report
        path: ./pytest.xml

but in script, coverage report is being overwritten in coverage.xml, how do i generate coverage report for all 3 app_layer, core, model combined?

Upvotes: -2

Views: 81

Answers (1)

Dunes
Dunes

Reputation: 40703

From the docs, add --cov-append to any subsequent test runs.

Upvotes: 0

Related Questions