diff --git a/.github/workflows/terraform_build.yaml b/.github/workflows/terraform_build.yaml index daac0ae1a..03c52a619 100644 --- a/.github/workflows/terraform_build.yaml +++ b/.github/workflows/terraform_build.yaml @@ -12,8 +12,8 @@ jobs: - name: Test with pytest run: | - ./scripts/test - ./scripts/test_v2 --no_build + ./scripts/test --do-cov --show-warnings + ./scripts/test_v2 --no_build --do-cov --show-warnings - name: Run codacy-coverage-reporter uses: codacy/codacy-coverage-reporter-action@master diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 755cb7307..a0d5dc950 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -64,7 +64,7 @@ services: - API_GATEWAY_STAGE_NAME=test - AWS_GCS_KEY_SECRET_ARN=testing - AWS_SECRETSMANAGER_URL=http://motoserver:50000 - entrypoint: wait_for_postgres.sh pytest --timeout 480 -vv --cov-report term --cov=app + entrypoint: wait_for_postgres.sh pytest --timeout 480 -vv --cov-report term depends_on: - test_database_12 - motoserver diff --git a/scripts/test b/scripts/test index 1ef108f37..7fcc16587 100755 --- a/scripts/test +++ b/scripts/test @@ -6,6 +6,9 @@ set -e # Default values POSITIONAL=() BUILD=true +DO_COV= +DISABLE_WARNINGS="--disable-warnings" +SHOW_STDOUT= # extracting cmd line arguments while [[ $# -gt 0 ]] do @@ -24,6 +27,18 @@ do SLOW=--with-slow-tests shift # past argument ;; + --do-cov) + DO_COV=--cov=app + shift # past argument + ;; + --show-warnings) + DISABLE_WARNINGS= + shift # past argument + ;; + --show-stdout) + SHOW_STDOUT=--capture=no + shift # past argument + ;; --moto-port=*) # prevent port binding issues by explicitly setting the motoserver s3 port # https://developer.apple.com/forums/thread/682332 @@ -38,6 +53,11 @@ do done set -- "${POSITIONAL[@]}" # restore positional parameters +# If no tests specified, do whole tests directory +args=$* +if [ $# -eq 0 ]; then + args=tests +fi if [ "${BUILD}" = true ]; then docker build -t batch_gdal-python_test . -f batch/gdal-python.dockerfile @@ -48,7 +68,9 @@ if [ "${BUILD}" = true ]; then fi set +e -docker-compose -f docker-compose.test.yml --project-name gfw-data-api_test run --rm --name app_test app_test $HANGING $SLOW --cov-report xml:/app/tests/cobertura.xml tests/"$*" + +# Everything from "--cov-report on" become the arguments to the pytest run inside the docker. +docker-compose -f docker-compose.test.yml --project-name gfw-data-api_test run --rm --name app_test app_test --cov-report xml:/app/tests/cobertura.xml $HANGING $SLOW $DO_COV $DISABLE_WARNINGS $SHOW_STDOUT $args exit_code=$? docker-compose -f docker-compose.test.yml --project-name gfw-data-api_test down --remove-orphans exit $exit_code diff --git a/scripts/test_v2 b/scripts/test_v2 index 37bda24f7..60e4977b9 100755 --- a/scripts/test_v2 +++ b/scripts/test_v2 @@ -6,6 +6,9 @@ set -e # Default values POSITIONAL=() BUILD=true +DO_COV= +DISABLE_WARNINGS="--disable-warnings" +SHOW_STDOUT= # extracting cmd line arguments while [[ $# -gt 0 ]] do @@ -16,12 +19,16 @@ do BUILD=false shift # past argument ;; - --without-hanging-tests) - HANGING=--without-hanging-tests + --do-cov) + DO_COV=--cov=app shift # past argument ;; - --with-slow-tests) - SLOW=--with-slow-tests + --show-warnings) + DISABLE_WARNINGS= + shift # past argument + ;; + --show-stdout) + SHOW_STDOUT=--capture=no shift # past argument ;; --moto-port=*) @@ -38,6 +45,11 @@ do done set -- "${POSITIONAL[@]}" # restore positional parameters +# If no tests specified, do whole tests_v2 directory +args=$* +if [ $# -eq 0 ]; then + args=tests_v2 +fi if [ "${BUILD}" = true ]; then docker build -t batch_gdal-python_test . -f batch/gdal-python.dockerfile @@ -48,7 +60,9 @@ if [ "${BUILD}" = true ]; then fi set +e -docker-compose -f docker-compose.test.yml --project-name gfw-data-api_test run --rm --name app_test app_test --cov-report xml:/app/tests_v2/cobertura.xml tests_v2/"$*" + +# Everything from "--cov-report on" become the arguments to the pytest run inside the docker. +docker-compose -f docker-compose.test.yml --project-name gfw-data-api_test run --rm --name app_test app_test --cov-report xml:/app/tests_v2/cobertura.xml $DO_COV $DISABLE_WARNINGS $SHOW_STDOUT $args exit_code=$? docker-compose -f docker-compose.test.yml --project-name gfw-data-api_test down --remove-orphans exit $exit_code