Repository navigation
100 lines (88 loc) · 2.82 KB
/
Copy pathtest-python.yml
File metadata and controls
100 lines (88 loc) · 2.82 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
88
89
90
91
92
93
94
95
96
97
98
99
100
# Runs automated tests on the Python backend with pytest
# Sample workflow content to call this:
#
# on:
# workflow_dispatch:
# push:
# branches: ["feature**"]
#
# jobs:
# test-python:
# uses: PSDI-UK/psdi-github-workflows-public/.github/workflows/test-python.yml@VERSION
# with:
# source_dir: PROJECT_NAME
# test_on_mac: true
name: Test Python
run-name: Test Python
on:
workflow_call:
inputs:
source_dir:
description: "The directory within the project containing the Python source code"
required: true
type: string
test_on_mac:
description: "Whether or not to additionally run tests on macos-latest"
required: false
default: false
type: boolean
python_version:
description: "The version of Python to use for tests"
required: false
default: "3.12"
type: string
require_node:
description: "Whether or not to install Node for use with tests (generally not needed for the backend tests here)"
required: false
default: false
type: boolean
node_version:
description: "If require_node=true, the version of Node to use for tests (unused if require_node=false)"
required: false
default: "16.x"
type: string
permissions:
contents: read
jobs:
tests:
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.secondary }}
strategy:
matrix:
os: [ubuntu-latest]
secondary: [false]
include:
- os: [macos-latest]
if: ${{ inputs.test_on_mac }}
secondary: true
steps:
- name: Checkout repo
uses: actions/checkout@v6
- name: Set up Node ${{ inputs.node_version }}
uses: actions/setup-node@v6
with:
node-version: ${{ inputs.node_version }}
- name: Set up Python ${{ inputs.python_version }}
uses: actions/setup-python@v6
with:
python-version: ${{ inputs.python_version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
pip install .[test]
- name: Test non-GUI code with pytest
run: |
pytest tests/python
# Save coverage report to coverage.json
- name: Lint with flake8
if: ${{ ! matrix.secondary }}
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 tests ${{ inputs.source_dir }} --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings
flake8 tests ${{ inputs.source_dir }} --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics
- name: Test building the package
run: |
pip install build
python -m build