-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (78 loc) · 2.37 KB
/
python-tests.yml
File metadata and controls
87 lines (78 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: Reusable Python Tests
on:
workflow_call:
inputs:
python-versions:
description: JSON array of Python versions.
required: false
type: string
default: '["3.11","3.12","3.13"]'
install-spec:
description: Pip install spec, e.g. .[dev]
required: false
type: string
default: ".[dev]"
coverage-target:
description: Coverage target path (empty disables coverage flags).
required: false
type: string
default: ""
coverage-threshold:
description: Coverage fail-under percentage.
required: false
type: number
default: 85
pytest-args:
description: Additional pytest args.
required: false
type: string
default: "-q"
install-node:
description: Whether to install Node.js before tests.
required: false
type: boolean
default: false
node-version:
description: Node.js version if install-node is true.
required: false
type: string
default: "20"
jobs:
pytest:
name: Pytest (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ${{ fromJSON(inputs.python-versions) }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Setup Node.js
if: ${{ inputs.install-node }}
uses: actions/setup-node@v6
with:
node-version: ${{ inputs.node-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e "${{ inputs.install-spec }}"
python -m pip install pytest-cov
- name: Run tests with coverage
if: ${{ inputs.coverage-target != '' }}
run: |
python -m pytest \
--cov=${{ inputs.coverage-target }} \
--cov-report=term-missing \
--cov-fail-under=${{ inputs.coverage-threshold }} \
${{ inputs.pytest-args }}
- name: Run tests without coverage
if: ${{ inputs.coverage-target == '' }}
run: python -m pytest ${{ inputs.pytest-args }}