Documentation #686
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# This workflow will install Python dependencies, run tests | |
# and lint with a variety of Python versions | |
# For more information see: | |
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | |
name: Unitest with pytest | |
on: # yamllint disable-line rule:truthy | |
pull_request_target: | |
types: | |
- opened | |
- edited | |
- synchronize | |
- reopened | |
workflow_call: | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [macos-latest, windows-latest] | |
python-version: ["3.12"] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
# This is the version of the action for setting up Python, | |
# not the Python version. | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Check to make sure that the module is in your Python path | |
run: | | |
echo $PYTHONPATH | |
# You can test your matrix by printing the current Python version | |
- name: Display Python version | |
run: python -c "import sys; print(sys.version)" | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip setuptools wheel | |
python -m pip install pytest | |
pip install -r requirements.txt | |
- name: Version check | |
run: | |
pytest --version | |
- name: Unitest with pytest | |
# yamllint disable rule:line-length | |
run: | |
python -m pytest . -v -rP --doctest-modules --junitxml=junit/test-results-${{ matrix.os }}-${{ matrix.python-version }}.xml --cov-report term-missing --cov-fail-under=80 --cov=./ --cov-report html:test-coverage-${{ matrix.os }}-${{ matrix.python-version }}.html | |
# yamllint enable rule:line-length | |
- name: Upload pytest test artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
# Name of the artifact to upload. | |
# Optional. Default is 'artifact' | |
name: | |
pytest-results-${{ matrix.os }}-${{ matrix.python-version }} | |
path: | |
junit/test-results-${{ matrix.os }}-${{ matrix.python-version }}.xml | |
# If true, an artifact with a matching name will be deleted before | |
# a new one is uploaded. If false, the action will fail if an | |
# artifact for the given name already exists. Does not fail if | |
# the artifact does not exist. Optional. Default is 'false' | |
overwrite: false | |
- name: Upload pytest coverage artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: | |
pytest-coverage-${{ matrix.os }}-${{ matrix.python-version }} | |
path: | |
test-coverage-${{ matrix.os }}-${{ matrix.python-version }}.html | |
# The retention-days value cannot exceed the retention | |
# limit set by the repository, organization, or enterprise. | |
# You can define a custom retention period for individual | |
# artifacts created by a workflow. When using a workflow to | |
# create a new artifact, you can use retention-days with the | |
# upload-artifact action. | |
retention-days: 2 | |
# If true, an artifact with a matching name will be deleted | |
# before a new one is uploaded. If false, the action will | |
# fail if an artifact for the given name already exists. | |
# Does not fail if the artifact does not exist. | |
# Optional. Default is 'false' | |
overwrite: false | |
# Use always() to always run this step to publish test results | |
# when there are test failures | |
if: ${{ always() }} |