diff --git a/.github/workflows/test-and-tag.yml b/.github/workflows/test-and-tag.yml index 6341195..53a2a4c 100644 --- a/.github/workflows/test-and-tag.yml +++ b/.github/workflows/test-and-tag.yml @@ -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 diff --git a/README.md b/README.md index 835e1de..6558b7a 100644 --- a/README.md +++ b/README.md @@ -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): diff --git a/pyproject.toml b/pyproject.toml index 02f5d72..1121fdc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", @@ -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 +""" diff --git a/requirements-test.txt b/requirements-test.txt new file mode 100644 index 0000000..606a02d --- /dev/null +++ b/requirements-test.txt @@ -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