Skip to content

Commit 8cfc2e9

Browse files
Add pytest GitHub Actions workflow
1 parent 1b417af commit 8cfc2e9

File tree

3 files changed

+100
-27
lines changed

3 files changed

+100
-27
lines changed

.github/workflows/pytest.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Test with pytest
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
- dev
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
15+
cancel-in-progress: true
16+
17+
# TODO-TEMPLATE: Populate environment variables below
18+
# LIBRARY_BASE_REPO: The base repo with the C++ implementation, e.g. "NTIA/itm"
19+
# LIBRARY_RELEASE_TAG: The Git tag identifying a release. Can be a pre-release.
20+
# LIBRARY_DESTINATION_DIRECTORY: Path in this repo where shared library files should be placed
21+
env:
22+
LIBRARY_BASE_REPO: NTIA/proplib-template
23+
LIBRARY_RELEASE_TAG: v1.0
24+
LIBRARY_DESTINATION_DIRECTORY: 'src/ITS/PropLibTemplate/'
25+
26+
jobs:
27+
run-all-tests:
28+
name: ${{ matrix.platform.os-name }} / Py${{ matrix.py }}
29+
runs-on: ${{ matrix.platform.os-runner }}
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
platform:
34+
- os-name: 'Windows (64-bit)'
35+
os-runner: 'windows-latest'
36+
arch-id: 'x64'
37+
release-file-pattern: '*-x64.dll'
38+
- os-name: 'Windows (32-bit)'
39+
os-runner: 'windows-latest'
40+
arch-id: 'x86'
41+
release-file-pattern: '*-x86.dll'
42+
- os-name: 'macOS (intel/x64)'
43+
os-runner: 'macos-13'
44+
arch-id: 'x64'
45+
release-file-pattern: '*.dylib'
46+
- os-name: 'macOS (apple/arm64)'
47+
os-runner: 'macos-latest'
48+
arch-id: 'arm64'
49+
release-file-pattern: '*.dylib'
50+
- os-name: 'Linux (Ubuntu)'
51+
os-runner: 'ubuntu-latest'
52+
arch-id: 'x64'
53+
release-file-pattern: '*.so'
54+
py: # Python versions to test on all platforms
55+
- "3.9"
56+
- "3.10"
57+
- "3.11"
58+
- "3.12"
59+
steps:
60+
- name: Check out repository
61+
uses: actions/checkout@v4
62+
with:
63+
submodules: true
64+
65+
# Cache key is unique to the combination of runner OS + architecture (matrix.arch-id) + release tag
66+
- name: Restore ${{ env.LIBRARY_RELEASE_TAG }} binaries from cache if available
67+
id: cache-restore
68+
uses: actions/cache@v4
69+
with:
70+
key: ${{ runner.os }}-${{ matrix.platform.arch-id }}-${{ env.LIBRARY_RELEASE_TAG }}
71+
path: ${{ env.LIBRARY_DESTINATION_DIRECTORY}}/${{ matrix.platform.release-file-pattern }}
72+
73+
# Only the binaries required for the current platform are downloaded. Note that the distributed
74+
# wheel for proplib python packages includes all binaries, so that the wheel is inherently cross-platform.
75+
- name: Download required ${{ env.LIBRARY_RELEASE_TAG }} binaries
76+
if: ${{ steps.cache-restore.outputs.cache-hit != 'true' }}
77+
uses: robinraju/release-downloader@v1
78+
with:
79+
repository: ${{ env.LIBRARY_BASE_REPO }}
80+
tag: ${{ env.LIBRARY_RELEASE_TAG }}
81+
fileName: ${{ matrix.platform.release-file-pattern }}
82+
tarBall: false
83+
zipBall: false
84+
out-file-path: ${{ env.LIBRARY_DESTINATION_DIRECTORY }}
85+
86+
- name: Set up Python ${{ matrix.py }}
87+
uses: actions/setup-python@v5
88+
with:
89+
architecture: ${{ matrix.platform.arch-id }}
90+
python-version: ${{ matrix.py }}
91+
cache: 'pip'
92+
93+
- name: Install dependencies for testing
94+
run: python -m pip install -e .[tests]
95+
96+
- name: Run pytest
97+
run: pytest --cov-report=term-missing --no-cov-on-fail --cov

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- Make sure to update the [pypi-release-badge] and [pypi-release-link] URLs with
88
your package name on PyPI (NOT the repository name on GitHub!)
99
- This can only be added once there is a published version of the package on PyPI
10-
- The third badge is the Tox GitHub actions status.
10+
- The third badge is the pytest GitHub actions status.
1111
- Update the repository name in [gh-actions-test-badge] and [gh-actions-test-link]
1212
- The fourth badge displays open GitHub Issues
1313
- Update the repository name in [gh-issues-badge]
@@ -27,8 +27,8 @@
2727
-->
2828
[proplib-badge]: https://img.shields.io/badge/PropLib-badge?label=%F0%9F%87%BA%F0%9F%87%B8%20NTIA%2FITS&labelColor=162E51&color=D63E04
2929
[proplib-link]: https://ntia.github.io/propagation-library-wiki
30-
[gh-actions-test-badge]: https://img.shields.io/github/actions/workflow/status/NTIA/TODO-TEMPLATE/tox.yml?branch=main&logo=pytest&logoColor=ffffff&label=Tests&labelColor=162E51
31-
[gh-actions-test-link]: https://github.com/NTIA/TODO-TEMPLATE/actions/workflows/tox.yml
30+
[gh-actions-test-badge]: https://img.shields.io/github/actions/workflow/status/NTIA/TODO-TEMPLATE/pytest.yml?branch=main&logo=pytest&logoColor=ffffff&label=Tests&labelColor=162E51
31+
[gh-actions-test-link]: https://github.com/NTIA/TODO-TEMPLATE/actions/workflows/pytest.yml
3232
[pypi-release-badge]: https://img.shields.io/pypi/v/TODO-TEMPLATE?logo=pypi&logoColor=ffffff&label=Release&labelColor=162E51&color=D63E04
3333
[pypi-release-link]: https://pypi.org/project/TODO-TEMPLATE
3434
[gh-issues-badge]: https://img.shields.io/github/issues/NTIA/TODO-TEMPLATE?logo=github&label=Issues&labelColor=162E51

pyproject.toml

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ classifiers = [
3737
tests = [
3838
"pytest>=8.2.0,<9.0",
3939
"pytest-cov>=6.0.0,<7.0",
40-
"tox>=4.21.1,<5.0", # Keep in sync with tool.tox.min_version
4140
]
4241
dev = [
4342
"hatchling>=1.25.0,<2.0",
@@ -64,26 +63,3 @@ ignore-vcs = true
6463
[tool.cibuildwheel]
6564
test-command = "pytest ."
6665
test-requires = "pytest"
67-
68-
[tool.tox]
69-
min_version = "4.21.1"
70-
env_list = ["3.9", "3.10", "3.11", "3.12", "3.13"]
71-
skip_missing_interpreters = true # TODO override this in GHA
72-
73-
[tool.tox.env.testenv]
74-
description = "Run tests with pytest and generate coverage report"
75-
extras = "tests"
76-
commands = [
77-
"pytest",
78-
"--cov-report=term-missing",
79-
"--no-cov-on-fail",
80-
"--cov",
81-
{ replace = "posargs", extend = true },
82-
]
83-
84-
[tool.tox.gh.python] # tox-gh config for GitHub Actions testing
85-
"3.9" = ["3.9"]
86-
"3.10" = ["3.10"]
87-
"3.11" = ["3.11"]
88-
"3.12" = ["3.12"]
89-
"3.13" = ["3.13"]

0 commit comments

Comments
 (0)