Skip to content

Run Tests

Run Tests #50

Workflow file for this run

name: Run Tests
on:
pull_request:
# Run when PR is submitted to main branch
branches: [ main ]
push:
branches:
# Run when code is pushed to main branch
- main
schedule:
# Run every weekday at 2am
- cron: "0 2 * * 1-5"
workflow_dispatch:
# Run when manually triggered
permissions:
actions: read
contents: read
pull-requests: write
jobs:
test:
name: Unit Tests and Coverage
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/[email protected]
- name: Set up Python
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: Run tests
run: poetry run pytest
- name: Check Coverage
if: matrix.python-version == '3.10'
run: |
poetry run coverage run -m pytest
poetry run coverage xml
echo "COVERAGE_PERCENT=$(poetry run coverage report --format=total | awk '{print $NF}' | tr -d '%')" >> $GITHUB_ENV
- name: Python Coverage
uses: orgoro/[email protected]
# only if pull request or push
if: github.event_name == 'pull_request' && matrix.python-version == '3.10'
with:
# local path to a coverage xml file like the output of pytest --cov
coverageFile: "coverage.xml"
# github token
token: ${{ secrets.GITHUB_TOKEN }}
# the coverage threshold for average over all files [0,1]
thresholdAll: 0.7
- name: Dynamic Badges
if: matrix.python-version == '3.10'
uses: Schneegans/[email protected]
with:
# Your secret with the gist scope
auth: ${{ secrets.GIST_SECRET }}
# The ID of the gist to use
gistID: 8e54c78cf86c9b23df72f9f987282266
# The *.json or *.svg filename of the badge data
filename: template-python-project-coverage.json
# The left text of the badge
label: Coverage
# The right text of the badge
message: ${{ env.COVERAGE_PERCENT }} %
valColorRange: ${{ env.COVERAGE_PERCENT }}
maxColorRange: 100
minColorRange: 0
forceUpdate: true