Skip to content

Commit

Permalink
Merge pull request #145 from communitiesuk/bau/tox-testing
Browse files Browse the repository at this point in the history
Add matrix testing via tox
  • Loading branch information
samuelhwilliams committed Jun 17, 2024
2 parents 8f770bc + e51cda2 commit bdac2c1
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 8 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/test-and-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,28 @@ on:
jobs:
run-unit-tests:
runs-on: ubuntu-latest
strategy:
matrix:
# If updating this list of python versions, you also need to update tox config in pyproject.toml
python-version: ['3.10', '3.11', '3.12']
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- name: Setup python
id: setup_python
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements-test.txt
- name: Run tests
run: |
python -m venv .venv
source .venv/bin/activate && python -m pip install --upgrade pip && pip install -r requirements-dev.txt
pytest
tox
create-release:
runs-on: ubuntu-latest
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ Install pre-commit hook: https://github.com/communitiesuk/funding-service-design
If you add any packages needed by services that consume `fsd_utils`, add them into `pyproject.yaml`.

# Testing
[Testing in Python repos](https://github.com/communitiesuk/funding-service-design-workflows/blob/main/readmes/python-repos-testing.md)

Tests in this repository run using `pytest`, as per our standardise [Testing in Python repos](https://github.com/communitiesuk/funding-service-design-workflows/blob/main/readmes/python-repos-testing.md) practice.

However, because this is a shared utils library that can be installed under different conditions (mainly Python or Flask versions), we matrix test the combinations using [tox](https://tox.wiki/en/4.15.1/).

To run tests via tox, `pip install -r requirements-test.txt` and then simply run `tox`. To run suites in parallel, run eg `tox -p 8`.

# Releasing
To create a new release of funding-service-design-utils (note no longer need to manually update the version):
Expand Down
51 changes: 50 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "funding-service-design-utils"

version = "2.0.51"
version = "2.0.52"

authors = [
{ name="DLUHC", email="FundingServiceDesignTeam@levellingup.gov.uk" },
Expand All @@ -25,6 +25,7 @@ dependencies = [
"PyYAML>=6.0,<7.0",
"python-dotenv>=0.20.0,<0.21.0",
"rich>=12.4.4,<13.0.0",
# If adding support for a new major/minor Flask version below, remember to add a tox env to matrix test it.
"Flask>=2.1.1,<3.0.0",
"python-json-logger>=2.0.2,<3.0.0",
"gunicorn>=20.1.0,<21.0.0",
Expand All @@ -42,3 +43,51 @@ dependencies = [

[project.urls]
"Homepage" = "https://github.com/communitiesuk/funding-service-design-utils"

[tool.tox]
legacy_tox_ini = """
[tox]
envlist = py310-A, py310-B, py311-A, py311-B, py312-A, py312-B
[gh-actions]
python =
3.10: py310
3.11: py311
3.12: py312
[testenv]
commands = py.test
deps =
pytest
-r requirements-dev.txt
[testenv:py310-A]
basepython = python3.10
deps = {[testenv]deps}
Flask>=2.2,<2.3
[testenv:py310-B]
basepython = python3.10
deps = {[testenv]deps}
Flask>=2.3,<3.0
[testenv:py311-A]
basepython = python3.11
deps = {[testenv]deps}
Flask>=2.2,<2.3
[testenv:py311-B]
basepython = python3.11
deps = {[testenv]deps}
Flask>=2.3,<3.0
[testenv:py312-A]
basepython = python3.12
deps = {[testenv]deps}
Flask>=2.2,<2.3
[testenv:py312-B]
basepython = python3.12
deps = {[testenv]deps}
Flask>=2.3,<3.0
"""
3 changes: 3 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This file installs the dependencies required for running tests via tox, which we use in our github workflow (CI).
tox==4.15.1
tox-gh-actions==3.2.0

0 comments on commit bdac2c1

Please sign in to comment.