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

Improve local testing #1245

Open
wants to merge 4 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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/`.

Expand Down
28 changes: 25 additions & 3 deletions backend/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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