Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 12 additions & 29 deletions .github/workflows/pytests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ on:
workflow_call:

inputs:
python_version:
description: 'Python version to use'
required: false
type: string
default: '3.11'

coverage:
description: 'Check the code coverage'
type: boolean
Expand All @@ -35,30 +41,12 @@ on:
type: boolean
default: false

install_package:
description: 'Install the package in editable mode before running tests (pip install -e .)'
required: false
type: boolean
default: false

packages:
description: 'Package or directory to measure coverage for (passed to --cov). Defaults to current directory.'
required: false
type: string
default: '.'

requirements_file:
description: 'Path to pip requirements file'
required: false
type: string
default: 'requirements.txt'

python_version:
description: 'Python version to use'
required: false
type: string
default: '3.11'

jobs:
pytests:
runs-on: ubuntu-latest
Expand All @@ -75,25 +63,20 @@ jobs:

- name: Install dependencies
run: |
if [ -f "${{ inputs.requirements_file }}" ]; then
pip install -r ${{ inputs.requirements_file }}
fi
pip install pytest-cov

- name: Install package
if: inputs.install_package == true
run: pip install -e .
pip install -U pip
pip install pytest pytest-cov
pip install '.[test]'

- name: Unit tests
if: inputs.coverage != true
run: python -m pytest
run: pytest

- name: Unit tests with coverage
if: inputs.coverage == true
run: python -m pytest --cov=${{ inputs.packages }} --cov-report=xml:coverage.xml --cov-report=term-missing --cov-fail-under=${{ inputs.coverage_threshold }} ${{ inputs.cov_branch && '--cov-branch' || '' }}
run: pytest --cov=${{ inputs.packages }} --cov-report=xml:coverage.xml --cov-report=term-missing --cov-fail-under=${{ inputs.coverage_threshold }} ${{ inputs.cov_branch && '--cov-branch' || '' }}

- name: Push coverage report to Codecov
if: inputs.coverage == true
if: inputs.coverage == true && inputs.python_version == '3.11'
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
18 changes: 18 additions & 0 deletions workflows_examples/pytests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Python Unit tests

on:
pull_request:
push:
branches: [main, master]

jobs:
tests:
strategy:
matrix:
python-version:
- "3.11"
- "3.12"

uses: RedHatInsights/processing-tools/.github/workflows/pytests.yaml@master
with:
python_version: ${{ matrix.python-version }}
Loading