Skip to content

29 add code coverage badges to readmemd (#241) #232

29 add code coverage badges to readmemd (#241)

29 add code coverage badges to readmemd (#241) #232

Workflow file for this run

name: Unit Tests
on:
pull_request:
branches:
- main
- "[0-9]+\\.[0-9]+\\.[0-9]+"
push:
branches:
- main
permissions:
contents: read
id-token: write # required for tokenless Codecov uploads via OIDC
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Codecov uses git history for blame/annotations
- name: 🐍 Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: 📦 Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: 📦 Cache Poetry virtualenv
uses: actions/cache@v4
with:
path: ~/.cache/pypoetry
key: ${{ runner.os }}-poetry-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-${{ matrix.python-version }}-
- name: 📦 Install dependencies with Poetry
run: poetry install --with dev
- name: 🔍 Lint with ruff
run: poetry run ruff check .
- name: 🧪 Run tests with coverage
run: |
export REPORT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
export REPORT_COMMIT="$(git rev-parse HEAD)"
poetry run pytest \
--cov=pytest_html_plus \
--cov-fail-under=39 \
--cov-report=term \
--cov-report=xml:coverage.xml \
--reruns 1 \
--ignore=tests/browser \
--generate-xml \
--xml-report final_xml_ubuntu.xml \
--git-branch "$REPORT_BRANCH" \
--git-commit "$REPORT_COMMIT" \
tests/
- name: ☂️ Upload coverage to Codecov
if: matrix.python-version == '3.12'
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
flags: unittests
name: codecov-pytest-html-plus
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
verbose: true
- name: 🧪 Run tests with warnings enabled
run: |
export REPORT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
export REPORT_COMMIT="$(git rev-parse HEAD)"
PYTHONWARNINGS=error poetry run pytest \
--cov=pytest_html_plus \
--cov-fail-under=39 \
--cov-report=term \
--reruns 1 \
--ignore=tests/browser \
--generate-xml \
--xml-report final_xml_ubuntu_warnings.xml \
--html-output=report_output_warnings \
--git-branch "$REPORT_BRANCH" \
--git-commit "$REPORT_COMMIT" \
tests/
- name: 📤 Upload HTML Report
if: always()
uses: actions/upload-artifact@v4
with:
name: report-${{ github.job }}-${{ github.run_number }}-${{ matrix.python-version }}
path: report_output/
- name: 📤 Upload HTML Warnings Report
if: always()
uses: actions/upload-artifact@v4
with:
name: report-warnings-${{ github.job }}-${{ github.run_number }}-${{ matrix.python-version }}
path: report_output_warnings/