From 95bdbe50a902ac81b5e24bd29e22d354ee891c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20S=C3=A9guin?= <162352622+francois-pass-culture@users.noreply.github.com> Date: Fri, 31 Jan 2025 10:30:56 +0100 Subject: [PATCH 1/6] (PC-34429)[API] ci: use pytest-split to parallelize tests in GHA --- .../workflows/dev_on_workflow_tests_api.yml | 19 +++++++---------- api/poetry.lock | 21 +++++++++++++++---- api/pyproject.toml | 1 + 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/.github/workflows/dev_on_workflow_tests_api.yml b/.github/workflows/dev_on_workflow_tests_api.yml index 7fc1ca1707c..10615d439ba 100644 --- a/.github/workflows/dev_on_workflow_tests_api.yml +++ b/.github/workflows/dev_on_workflow_tests_api.yml @@ -394,7 +394,7 @@ jobs: SLACK_BOT_TOKEN: ${{ steps.secrets.outputs.SLACK_BOT_TOKEN }} pytest: - name: "Pytest" + name: "Pytest ${{ matrix.pytest_args.description }} : ${{ matrix.group }}/4" env: RUN_ENV: tests DATABASE_URL_TEST: postgresql://pytest:pytest@postgres:5432/pass_culture @@ -407,14 +407,11 @@ jobs: fail-fast: false matrix: pytest_args: - [ - "tests/core/bookings tests/core/offers tests/core/finance", - "tests/core --ignore=tests/core/bookings --ignore=tests/core/offers --ignore=tests/core/finance", - "tests/routes -m 'not backoffice'", - "tests --ignore=tests/core --ignore=tests/routes", - "tests/routes/backoffice/collective_bookings_test.py tests/routes/backoffice/collective_offers_test.py tests/routes/backoffice/individual_bookings_test.py tests/routes/backoffice/offers_test.py tests/routes/backoffice/offerers_test.py -m 'backoffice'", - "tests/routes/backoffice -m 'backoffice' --ignore=tests/routes/backoffice/collective_bookings_test.py --ignore=tests/routes/backoffice/collective_offers_test.py --ignore=tests/routes/backoffice/individual_bookings_test.py --ignore=tests/routes/backoffice/offers_test.py --ignore=tests/routes/backoffice/offerers_test.py", - ] + - collection: "--ignore=tests/routes/backoffice" + description: "(without BO)" + - collection: "tests/routes/backoffice" + description: "(only BO)" + group: [1, 2, 3, 4] services: redis: image: redis:7-alpine @@ -502,14 +499,14 @@ jobs: run: | echo "Changing owner and group fort directory test" chown -R pcapi:pcapi /tests - - name: "Run tests" + - name: "Run pytest" uses: addnab/docker-run-action@v3 with: image: ${{ steps.compute-image-name.outputs.image_name }} shell: bash options: -e RUN_ENV -e DATABASE_URL_TEST -e REDIS_URL -e SQLALCHEMY_WARN_20 -v ${{ runner.workspace }}/pass-culture-main/api/tests/:/tests run: | - pytest ${{ matrix.pytest_args }} --durations=10 --junitxml='/tests/junit.xml' -vv + pytest ${{ matrix.pytest_args.collection }} --splits 4 --group ${{ matrix.group }} --durations=10 --junitxml='/tests/junit.xml' -vv - name: "Publish Test Report" uses: mikepenz/action-junit-report@v5 if: always() # always run even if the previous step fails diff --git a/api/poetry.lock b/api/poetry.lock index b3d774890e9..e7ebeb9c715 100644 --- a/api/poetry.lock +++ b/api/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 2.0.0 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.0.1 and should not be changed by hand. [[package]] name = "alembic" @@ -1124,7 +1124,6 @@ optional = false python-versions = ">=3.7" groups = ["dev"] files = [ - {file = "configobj-5.0.9-py2.py3-none-any.whl", hash = "sha256:1ba10c5b6ee16229c79a05047aeda2b55eb4e80d7c7d8ecf17ec1ca600c79882"}, {file = "configobj-5.0.9.tar.gz", hash = "sha256:03c881bbf23aa07bccf1b837005975993c4ab4427ba57f959afdd9d1a2386848"}, ] @@ -3745,7 +3744,6 @@ files = [ {file = "psycopg2-2.9.10-cp311-cp311-win_amd64.whl", hash = "sha256:0435034157049f6846e95103bd8f5a668788dd913a7c30162ca9503fdf542cb4"}, {file = "psycopg2-2.9.10-cp312-cp312-win32.whl", hash = "sha256:65a63d7ab0e067e2cdb3cf266de39663203d38d6a8ed97f5ca0cb315c73fe067"}, {file = "psycopg2-2.9.10-cp312-cp312-win_amd64.whl", hash = "sha256:4a579d6243da40a7b3182e0430493dbd55950c493d8c68f4eec0b302f6bbf20e"}, - {file = "psycopg2-2.9.10-cp313-cp313-win_amd64.whl", hash = "sha256:91fd603a2155da8d0cfcdbf8ab24a2d54bca72795b90d2a3ed2b6da8d979dee2"}, {file = "psycopg2-2.9.10-cp39-cp39-win32.whl", hash = "sha256:9d5b3b94b79a844a986d029eee38998232451119ad653aea42bb9220a8c5066b"}, {file = "psycopg2-2.9.10-cp39-cp39-win_amd64.whl", hash = "sha256:88138c8dedcbfa96408023ea2b0c369eda40fe5d75002c0964c78f46f11fa442"}, {file = "psycopg2-2.9.10.tar.gz", hash = "sha256:12ec0b40b0273f95296233e8750441339298e6a572f7039da5b260e3c8b60e11"}, @@ -4524,6 +4522,21 @@ files = [ [package.dependencies] pytest = ">=6.2.5" +[[package]] +name = "pytest-split" +version = "0.10.0" +description = "Pytest plugin which splits the test suite to equally sized sub suites based on test execution time." +optional = false +python-versions = "<4.0,>=3.8.1" +groups = ["dev"] +files = [ + {file = "pytest_split-0.10.0-py3-none-any.whl", hash = "sha256:466096b086a7147bcd423c6e6c2e57fc62af1c5ea2e256b4ed50fc030fc3dddc"}, + {file = "pytest_split-0.10.0.tar.gz", hash = "sha256:adf80ba9fef7be89500d571e705b4f963dfa05038edf35e4925817e6b34ea66f"}, +] + +[package.dependencies] +pytest = ">=5,<9" + [[package]] name = "python-dateutil" version = "2.9.0.post0" @@ -6393,4 +6406,4 @@ files = [ [metadata] lock-version = "2.1" python-versions = ">=3.11,<4.0" -content-hash = "aff2be2a0a73a8cc11dc6f57a1ae9f7fabe497bafbbe9cb852bd37651b6ac3ae" +content-hash = "d55c59a191c9189322488f732b330140bec352740ff01f6d5787a6a96ff0bdd8" diff --git a/api/pyproject.toml b/api/pyproject.toml index 1e132ecf441..cde35edb69f 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -102,6 +102,7 @@ pytest-dotenv = "^0.5.2" pytest-flask = "^1.3.0" pytest-mock = "^3.14.0" pytest-socket = "^0.7.0" +pytest-split = "^0.10.0" requests-mock = "^1.12.1" types-protobuf = "^5.29.1.20241207" types-python-dateutil = "^2.9.0.20241206" From 2826947e2455af43e91d336796ef4d91012f1d4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20S=C3=A9guin?= <162352622+francois-pass-culture@users.noreply.github.com> Date: Thu, 6 Feb 2025 11:36:48 +0100 Subject: [PATCH 2/6] (BSR) ci: remove unnecessary pytest argument --- .github/workflows/dev_on_workflow_tests_api.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev_on_workflow_tests_api.yml b/.github/workflows/dev_on_workflow_tests_api.yml index 10615d439ba..fce0ec007a2 100644 --- a/.github/workflows/dev_on_workflow_tests_api.yml +++ b/.github/workflows/dev_on_workflow_tests_api.yml @@ -506,7 +506,7 @@ jobs: shell: bash options: -e RUN_ENV -e DATABASE_URL_TEST -e REDIS_URL -e SQLALCHEMY_WARN_20 -v ${{ runner.workspace }}/pass-culture-main/api/tests/:/tests run: | - pytest ${{ matrix.pytest_args.collection }} --splits 4 --group ${{ matrix.group }} --durations=10 --junitxml='/tests/junit.xml' -vv + pytest ${{ matrix.pytest_args.collection }} --splits 4 --group ${{ matrix.group }} --durations=10 --junitxml='/tests/junit.xml' - name: "Publish Test Report" uses: mikepenz/action-junit-report@v5 if: always() # always run even if the previous step fails From e10f190d2702b57d83bcbb3f95e0432e179b1853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20S=C3=A9guin?= <162352622+francois-pass-culture@users.noreply.github.com> Date: Thu, 6 Feb 2025 11:37:18 +0100 Subject: [PATCH 3/6] (BSR) ci: don't publish Pytest report if successful --- .github/workflows/dev_on_workflow_tests_api.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/dev_on_workflow_tests_api.yml b/.github/workflows/dev_on_workflow_tests_api.yml index fce0ec007a2..0934dc03104 100644 --- a/.github/workflows/dev_on_workflow_tests_api.yml +++ b/.github/workflows/dev_on_workflow_tests_api.yml @@ -514,6 +514,7 @@ jobs: report_paths: "${{ runner.workspace }}/pass-culture-main/api/tests/junit.xml" check_name: "Pytest Report" fail_on_failure: true + skip_success_summary: true - name: "Slack Notification" if: ${{ failure() && github.ref == 'refs/heads/master' }} uses: slackapi/slack-github-action@v1.27.0 From 43fea3b7ddf49edcd7dd882170211662ff9d545e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20S=C3=A9guin?= <162352622+francois-pass-culture@users.noreply.github.com> Date: Thu, 6 Feb 2025 11:50:43 +0100 Subject: [PATCH 4/6] (BSR) ci: don't publish Docker build summary on PR and push workflows --- .github/workflows/dev_on_workflow_build_docker_image.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/dev_on_workflow_build_docker_image.yml b/.github/workflows/dev_on_workflow_build_docker_image.yml index 984247faaa0..5716c038e65 100644 --- a/.github/workflows/dev_on_workflow_build_docker_image.yml +++ b/.github/workflows/dev_on_workflow_build_docker_image.yml @@ -23,6 +23,7 @@ on: env: registry: europe-west1-docker.pkg.dev/passculture-infra-prod/pass-culture-artifact-registry + DOCKER_BUILD_SUMMARY: false jobs: build-docker-image: From fac7646ba3c53b9702c8eeb176e9335bab833656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20S=C3=A9guin?= <162352622+francois-pass-culture@users.noreply.github.com> Date: Fri, 7 Feb 2025 08:54:04 +0100 Subject: [PATCH 5/6] DONOTMERGE trigger workflow --- api/src/pcapi/flask_app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/src/pcapi/flask_app.py b/api/src/pcapi/flask_app.py index 2b165023f40..87594666dde 100644 --- a/api/src/pcapi/flask_app.py +++ b/api/src/pcapi/flask_app.py @@ -1,3 +1,5 @@ +# un tout petit changement ! + import logging import os import sys From d2a4cbc30b017c26645949b20b6618a540b4f31b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20S=C3=A9guin?= <162352622+francois-pass-culture@users.noreply.github.com> Date: Fri, 7 Feb 2025 17:51:24 +0100 Subject: [PATCH 6/6] WITHOUT stored test_durations