diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 03e4ba1ef6..be1512a39d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,7 +28,7 @@ jobs: - name: Lint run: docker compose exec -T backend bash /app/scripts/lint.sh - name: Run tests - run: docker compose exec -T backend bash /app/tests-start.sh "Coverage for ${{ github.sha }}" + run: docker compose exec -T backend bash /app/tests-start.sh --message="Coverage for ${{ github.sha }}" - run: docker compose down -v --remove-orphans - name: Store coverage files uses: actions/upload-artifact@v4 diff --git a/backend/README.md b/backend/README.md index 27aabab578..8c30404b75 100644 --- a/backend/README.md +++ b/backend/README.md @@ -138,8 +138,22 @@ Nevertheless, if it doesn't detect a change but a syntax error, it will just sto To test the backend run: ```console -$ bash ./scripts/test.sh +$ bash ./scripts/start-test.sh ``` +...or inside docker: +```console +$ docker compose exec backend bash ./tests-start.sh +``` + +To run a specific test: +```console +$ bash ./tests-start.sh app/tests/api/routes/test_users.py::test_update_user +``` +To run a specific test without coverage: +```console +$ bash ./tests-start.sh --no-coverage app/tests/api/routes/test_users.py::test_update_user +``` + The tests run with Pytest, modify and add tests to `./backend/app/tests/`. diff --git a/backend/scripts/test.sh b/backend/scripts/test.sh index df23f702e3..72d3fea5ac 100755 --- a/backend/scripts/test.sh +++ b/backend/scripts/test.sh @@ -3,6 +3,28 @@ set -e set -x -coverage run --source=app -m pytest -coverage report --show-missing -coverage html --title "${@-coverage}" +NO_COVERAGE=0 +MESSAGE="Coverage Report" + +while [[ "$#" -gt 0 ]]; do + case $1 in + --no-coverage) + NO_COVERAGE=1 + ;; + --message=*) + MESSAGE="${1#*=}" + ;; + *) + TEST_PATH="$1" + ;; + esac + shift +done + +if [ $NO_COVERAGE -eq 0 ]; then + coverage run --source=app -m pytest ${TEST_PATH} + coverage report --show-missing + coverage html --title "$MESSAGE" +else + pytest ${TEST_PATH} +fi