Skip to content

Run unit tests with coverage analysis #69

Run unit tests with coverage analysis

Run unit tests with coverage analysis #69

Workflow file for this run

# Copyright (c) 2023-2024 tracetronic GmbH
#
# SPDX-License-Identifier: MIT
name: Test
run-name: Run unit tests with coverage analysis
on:
push:
branches:
- main
pull_request:
jobs:
test:
strategy:
matrix:
py_version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.py_version }}
- name: Install virtual environment
run: pip3 install poetry
- name: Ensure Python version
run: poetry env use ${{ matrix.py_version }}
- name: Install dependencies
run: poetry install --without workflow --no-root
- name: Execute Tests and create test coverage report
run: poetry run pytest tests --cov=testguide_report_generator --cov-report=xml:coverage-${{ matrix.py_version }}.xml
- name: Execute Test
run: poetry run pytest tests
- name: Upload test coverage report
uses: actions/upload-artifact@v4
with:
name: test-coverage-report-${{ matrix.py_version }}
path: coverage-${{ matrix.py_version }}.xml
publish-coverage:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
needs: test
env:
ARTIFACT_FOLDER: test-coverage-report
steps:
- name: Download test coverage report
uses: actions/download-artifact@v4
with:
path: ${{ env.ARTIFACT_FOLDER }}
pattern: ${{ env.ARTIFACT_FOLDER }}-*
merge-multiple: true
- name: Find latest coverage report
run: |
latest_file=$(ls ${{ env.ARTIFACT_FOLDER }}/ | sort -V | tail -n 1)
echo "LATEST_COVERAGE_FILE=$latest_file" >> $GITHUB_ENV
echo "Latest coverage file version: $latest_file"
- name: Get Cover
uses: orgoro/coverage@v3
with:
coverageFile: ${{ env.ARTIFACT_FOLDER }}/${{ env.LATEST_COVERAGE_FILE }}
token: ${{ secrets.GITHUB_TOKEN }}
thresholdAll: 0.99