From b509feeba0716a102482228b21c42251f2ef92ba Mon Sep 17 00:00:00 2001 From: George McCabe <23407799+georgemccabe@users.noreply.github.com> Date: Thu, 7 Jul 2022 09:07:30 -0600 Subject: [PATCH] per #685, run pytests with markers to subset tests into groups --- .github/actions/run_tests/entrypoint.sh | 7 ++++--- .github/jobs/get_use_cases_to_run.sh | 10 ++++++++-- .github/parm/pytest_groups.txt | 2 ++ internal_tests/pytests/pytest.ini | 4 ++-- 4 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 .github/parm/pytest_groups.txt diff --git a/.github/actions/run_tests/entrypoint.sh b/.github/actions/run_tests/entrypoint.sh index 53692ab10f..e91e3977d7 100644 --- a/.github/actions/run_tests/entrypoint.sh +++ b/.github/actions/run_tests/entrypoint.sh @@ -33,7 +33,7 @@ fi # # running unit tests (pytests) # -if [ "$INPUT_CATEGORIES" == "pytests" ]; then +if [ "$INPUT_CATEGORIES" == pytests* ]; then export METPLUS_ENV_TAG="pytest" export METPLUS_IMG_TAG=${branch_name} echo METPLUS_ENV_TAG=${METPLUS_ENV_TAG} @@ -55,8 +55,9 @@ if [ "$INPUT_CATEGORIES" == "pytests" ]; then -f .github/actions/run_tests/Dockerfile.run \ . - echo Running Pytests - command="export METPLUS_PYTEST_HOST=docker; cd internal_tests/pytests; /usr/local/envs/pytest/bin/pytest -vv --cov=../../metplus" + marker=`echo $INPUT_CATEGORIES | awk -F_ '{print $2}'` + echo Running Pytests marker=$marker + command="export METPLUS_PYTEST_HOST=docker; cd internal_tests/pytests; /usr/local/envs/pytest/bin/pytest -vv --cov=../../metplus -m $marker" time_command docker run -v $WS_PATH:$GITHUB_WORKSPACE --workdir $GITHUB_WORKSPACE $RUN_TAG bash -c "$command" exit $? fi diff --git a/.github/jobs/get_use_cases_to_run.sh b/.github/jobs/get_use_cases_to_run.sh index 39c250474c..0c0790e4a2 100755 --- a/.github/jobs/get_use_cases_to_run.sh +++ b/.github/jobs/get_use_cases_to_run.sh @@ -1,6 +1,7 @@ #! /bin/bash use_case_groups_filepath=.github/parm/use_case_groups.json +pytests_groups_filepath=.github/parm/pytest_groups.txt # set matrix to string of an empty array in case no use cases will be run matrix="[]" @@ -31,12 +32,17 @@ fi if [ "$run_unit_tests" == "true" ]; then echo Adding unit tests to list to run + pytests="" + for x in `cat $pytests_groups_filepath`; do + pytests=$pytests"\"pytests_$x\"," + done + # if matrix is empty, set to an array that only includes pytests if [ "$matrix" == "[]" ]; then - matrix="[\"pytests\"]" + matrix="[${pytests:0: -1}]" # otherwise prepend item to list else - matrix="[\"pytests\", ${matrix:1}" + matrix="[${pytests}${matrix:1}" fi fi diff --git a/.github/parm/pytest_groups.txt b/.github/parm/pytest_groups.txt new file mode 100644 index 0000000000..5a7c92618e --- /dev/null +++ b/.github/parm/pytest_groups.txt @@ -0,0 +1,2 @@ +wrapper +util diff --git a/internal_tests/pytests/pytest.ini b/internal_tests/pytests/pytest.ini index 98138a6620..aef09b9d38 100644 --- a/internal_tests/pytests/pytest.ini +++ b/internal_tests/pytests/pytest.ini @@ -1,4 +1,4 @@ [pytest] markers = - util - wrapper + util: custom marker for testing metplus/util logic + wrapper: custom marker for testing metplus/wrapper logic