Seamless integration of tox into GitHub Actions
npx @tessl/cli install tessl/pypi-tox-gh-actions@3.3.0A tox plugin that enables seamless integration between tox testing environments and GitHub Actions workflows. The plugin automatically detects which tox environments to run based on the Python version and other factors configured in GitHub Actions matrix strategies, eliminating the need for manual environment selection and enabling efficient parallel testing across multiple Python versions and platforms.
pip install tox-gh-actionsThe plugin operates automatically when installed. The only direct import typically needed is for version information:
from tox_gh_actions import __version__The plugin operates automatically once installed - no direct Python API calls are needed. Configuration is done through tox configuration files.
Add a [gh-actions] section to your tox.ini, setup.cfg, or pyproject.toml:
[tox]
envlist = py37, py38, py39, py310, py311, mypy
[gh-actions]
python =
3.7: py37
3.8: py38
3.9: py39
3.10: py310
3.11: py311, mypy
[testenv]
# Your test configurationname: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
- name: Test with tox
run: toxThe plugin integrates with tox's plugin system through three main hooks:
[gh-actions] and [gh-actions:env] sections from tox configuration filesThe plugin operates transparently - it detects the GitHub Actions environment, reads the configuration, and automatically overrides tox's envlist to run only the environments appropriate for the current Python version and environment variables.
Access to package version information.
__version__: strMaps Python versions to tox environments in the [gh-actions] section. This is the primary way users configure the plugin.
[gh-actions]
python =
3.7: py37
3.8: py38, flake8
3.9: py39
3.10: py310, mypy
3.11: py311
pypy-3.7: pypy3
pyston-3.8: pyston38Supported version formats:
3.8: Specific major.minor version3: Major version onlypypy-3.7: PyPy with specific versionpyston-3.8: Pyston with specific versionVersion matching rules:
3 and 3.8 are configured, 3.8 takes precedence for Python 3.83.8 before 3Maps environment variable values to tox factors in the [gh-actions:env] section.
[gh-actions:env]
PLATFORM =
ubuntu-latest: linux
macos-latest: macos
windows-latest: windows
DATABASE =
postgresql: pg
mysql: mysqlEnvironment variable rules:
The plugin automatically handles various scenarios:
Environment Detection:
GITHUB_ACTIONS=true environment variable is presentConfiguration Handling:
-e option or TOXENV variable[gh-actions] configuration is presentLog Management:
Common Usage Patterns:
# Plugin automatically selects environments based on Python version
tox
# Plugin respects explicit environment selection
tox -e py38,py39
# Plugin respects TOXENV environment variable
TOXENV=py310,mypy tox[tox]
envlist = py{38,39,310}-{linux,macos,windows}
[gh-actions]
python =
3.8: py38
3.9: py39
3.10: py310
[gh-actions:env]
PLATFORM =
ubuntu-latest: linux
macos-latest: macos
windows-latest: windows[tox]
envlist = py{38,39}-django{22,32,40}-{sqlite,postgres}
[gh-actions]
python =
3.8: py38
3.9: py39
[gh-actions:env]
DATABASE =
sqlite: sqlite
postgres: postgres
DJANGO_VERSION =
2.2: django22
3.2: django32
4.0: django40[tox]
requires =
tox-conda
tox-gh-actions
envlist = py38, py39, py310