Tests actions#

The tests actions allow to run the test suite for a Python library.

Test library action#

This action runs the test suite for a Python library. This action accepts markers, options, and post arguments to be passed to pytest before executing the test session.

Run a test suite using pytest.

Source code for this action

Input

Description

Required

Type

Default

python-version

Python version used for installing and running pytest.

False

string

3.10

use-python-cache

Whether to use the Python cache for installing previously downloaded libraries. If true, previously downloaded libraries are installed from the Python cache. If false, libraries are downloaded from the PyPI index.

False

boolean

True

pytest-markers

Set of pytest markers in the form of a string. These markers are used to discretize tests when running the test session.

False

string

pytest-extra-args

Set of additional pytest arguments in the form of a string.

False

pytest-postargs

Directory of the test suite and the level of verbosity.

False

string

tests -vv

requires-xvfb

Whether to install X Virtual Frame Buffer (XVFB) and run the whole test session using XVFB. The default value is false.

False

boolean

False

checkout

Whether to clone the repository in the CI/CD machine. Default value is true.

False

boolean

True

skip-install

Skip installation process. This should be set to false when using poetry as the build-backend because it should be false with poetry as build-backend. The default value is false.

boolean

False

Examples#

Testing library with different operating systems and Python versions
tests:
  name: "Testing library with different operating systems and Python versions"
  runs-on: ${{ matrix.os }}
  strategy:
     matrix:
         os: [ubuntu-latest, windows-latest]
         python-version: ['3.7', '3.8', '3.9', '3.10']
     fail-fast: false
  steps:
    - name: "Run pytest"
      uses: ansys/actions/tests-pytest@v6.0
      with:
        pytest-markers: "-k 'mocked'"
        pytest-extra-args: "--cov=ansys.<library> --cov-report=term --cov-report=html:.cov/html"
Optimized testing with different operating systems and Python versions
tests:
  name: "Optimized testing with different operating systems and Python versions"
  runs-on: ${{ matrix.os }}
  strategy:
     matrix:
         os: [ubuntu-latest, windows-latest]
         cfg:
           - {python-version: '3.7', markers: '-m fast', extra-args: ''}
           - {python-version: '3.8', markers: '-m plotting', extra-args: ''}
           - {python-version: '3.9', markers: '', extra-args: '--doctest-modules src'}
           - {python-version: '3.10', markers: '', extra-args: '--cov=ansys.<library> --cov-report=term --cov-report=html:.cov/html'}
     fail-fast: false
  steps:

    - name: "Login into the GitHub container registry"
      uses: docker/login-action@v2.1.0
      with:
        registry: ghcr.io
        username: ${{ secrets.GH_USERNAME }}
        password: ${{ secrets.GITHUB_TOKEN }}

    - name: "Pull, launch and verify desired Ansys service"
      run: ...
      env:
        LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }}

    - name: "Run pytest with desired markers and extra arguments"
      uses: ansys/actions/tests-pytest@v6.0
      with:
        requires-xvfb: true
        pytest-markers: ${{ matrix.cfg.markers }}
        pytest-extra-args: ${{ matrix.cfg.extra-args }}