GitHub Actions Workflow Generator · Tutorial
How to test a Python project on several versions and systems
7 min readintermediateUpdated
Your library should work for users on different Python versions and operating systems. You will set up a matrix that runs nine combinations in parallel, and a weekly scheduled run that catches breakage from new dependency releases.
What you need
- The GitHub Actions Generator
- A Python project with requirements.txt and pytest tests
Steps
Load the matrix example
It tests Python 3.11, 3.12 and 3.13 on Linux, Windows and macOS: nine jobs in parallel.
Check the version quoting
In the generated YAML the versions appear as
'3.11'in quotes. Without quotes, YAML reads 3.10 as the number 3.1, a classic mistake.matrix: os: [ubuntu-latest, windows-latest, macos-latest] python-version: ['3.11', '3.12', '3.13']Add a weekly run
The schedule
0 6 * * 1runs every Monday at 06:00 UTC, even when nobody pushes, so you find out when a new release of a dependency breaks your tests.Let all jobs finish
fail-fast: falsekeeps the other jobs running when one fails, so you see whether a problem affects one system or all of them.
Try it yourself
Opens the GitHub Actions Workflow Generator with this tutorial's sample loaded.
Common mistakes
- Paths that only work on Linux
- Windows jobs fail on hard-coded
/paths or shell commands likerm. Usepathlibin tests. - Testing every combination forever
- macOS runners use more of your minutes on private repositories. Test the oldest and newest Python on macOS if minutes are tight.
Next steps
Go back to the GitHub Actions Workflow Generator, or keep going with one of these: