If you are developing your application on GitHub, then you might want to consider using GitHub Actions for your CI/CD. In this tutorial we will cover how to use GitHub actions for testing multiple version of python and on different platforms.
Our example will include a FastAPI application, using pytest to run our tests, pylint for linting check, on python versions (3.8, 3.9, 3.10, 3.11) with (Windows, Mac, Linux) platforms. You can find this example on GitHub here.
First thing you will notice is under the .github/workflows
directory there is a file named python-app.yml
which is the YAML file that will be used for our GitHub Actions Pipeline.
In this file you will find the below break-down.
You will see that the key runs-on
uses the variable matrix.os
which has the array of operating systems to use. While the key python-versions
uses the variable matrix.python-version
that takes the array of python versions.
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
Underneath you will see multiple keys named run
each for installing dependencies, linting and testing.
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with pylint
run: |
pylint --recursive=y api --rcfile=.pylintrc
- name: Test with pytest
run: |
pytest api/
Every time you push a change to your repository this action will run.
To learn more about Python automation and testing using GitHub Actions you can visit this link.
Top comments (0)