Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PC-34429)[API] ci: use pytest-split to parallelize tests in GHA #16217

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/dev_on_workflow_build_docker_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 9 additions & 11 deletions .github/workflows/dev_on_workflow_tests_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -502,21 +499,22 @@ 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'
- name: "Publish Test Report"
uses: mikepenz/action-junit-report@v5
if: always() # always run even if the previous step fails
with:
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
Expand Down
21 changes: 17 additions & 4 deletions api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions api/src/pcapi/flask_app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# un tout petit changement !

import logging
import os
import sys
Expand Down
Loading