diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 555188911..28033cb4a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -27,7 +27,7 @@ Changes to `requirements.txt` should always be by pull request. - Add docstrings to all functions with a one-line description of its purpose. ### Format -Ensure that `./test/bin/lint.sh api` exits without errors. +Ensure that `./tests/bin/run-tests-docker.sh -- -l` exits without errors. ### Commit Messages 1. The subject line should be a phrase describing the commit and limited to 50 characters diff --git a/TESTING.md b/TESTING.md index c364360a1..26b292e5c 100644 --- a/TESTING.md +++ b/TESTING.md @@ -8,10 +8,12 @@ Run automated tests: ./test/bin/setup-integration-tests-ubuntu.sh ./test/bin/run-tests-ubuntu.sh ``` -* To skip linting, use `--no-lint` (`-L`) -* To skip unit tests, use `--no-unit` (`-U`) -* To skip integration tests, use `--no-integ` (`-I`) -* To skip abao tests, use `--no-abao` (`-A`) +All tests are executed by default. Subsets can be run using the filtering options: + +* To run linting, use `--lint` (`-l`) +* To run unit tests, use `--unit` (`-u`) +* To run integration tests, use `--integ` (`-i`) +* To run abao tests, use `--abao` (`-a`) * To pass any arguments to `py.test`, use `-- PYTEST_ARGS` See [py.test usage](https://docs.pytest.org/en/latest/usage.html) for more. @@ -27,7 +29,7 @@ Build scitran-core image and run automated tests in a docker container: #### Example Without rebuilding the image, run only integration tests matching `foo`, use the highest verbosity level for test output and jump into a python debugger session in case an assertion fails: ``` -./tests/bin/run-tests-docker.sh -B -- -L -U -A -- -k foo -vvv --pdb +./tests/bin/run-tests-docker.sh -B -- -i -- -k foo -vvv --pdb ``` ### Tools diff --git a/tests/bin/run-tests-docker.sh b/tests/bin/run-tests-docker.sh index f27b034f6..afcd42c22 100755 --- a/tests/bin/run-tests-docker.sh +++ b/tests/bin/run-tests-docker.sh @@ -34,13 +34,13 @@ function main() { shift done - trap clean_up EXIT - if ${DOCKER_BUILD}; then echo "Building scitran-core:run-tests ..." docker build -t scitran-core:run-tests . fi + trap clean_up EXIT + docker network create scitran-core-test-network # Launch Mongo instance diff --git a/tests/bin/run-tests-ubuntu.sh b/tests/bin/run-tests-ubuntu.sh index 6f870493f..8c7d94fa5 100755 --- a/tests/bin/run-tests-ubuntu.sh +++ b/tests/bin/run-tests-ubuntu.sh @@ -11,14 +11,17 @@ Run scitran-core tests Usage: $0 [OPTION...] +Runs linting and all tests if no options are provided. +Runs subset of tests when using the filtering options. +Displays coverage report if all tests ran and passed. + Options: - -L, --no-lint Skip linting - -U, --no-unit Skip unit tests - -I, --no-integ Skip integration tests - -A, --no-abao Skip abao tests - -R, --no-report Skip coverage report - -h, --help Print this help and exit - -- PYTEST_ARGS Arguments passed to py.test + -l, --lint Run linting + -u, --unit Run unit tests + -i, --integ Run integration tests + -a, --abao Run abao tests + -h, --help Print this help and exit + -- PYTEST_ARGS Arguments passed to py.test Envvars: SCITRAN_PERSISTENT_DB_PORT (9001) @@ -33,31 +36,35 @@ EOF function main() { - local RUN_LINT=true - local RUN_UNIT=true - local RUN_INTEG=true - local RUN_ABAO=true + export RUN_ALL=true + local RUN_LINT=false + local RUN_UNIT=false + local RUN_INTEG=false + local RUN_ABAO=false local PYTEST_ARGS= - export RUN_REPORT=true - while [[ "$#" > 0 ]]; do case "$1" in - -L|--no-lint) RUN_LINT=false ;; - -U|--no-unit) RUN_UNIT=false ;; - -I|--no-integ) RUN_INTEG=false ;; - -A|--no-abao) RUN_ABAO=false ;; - -R|--no-report) RUN_REPORT=false ;; - -h|--help) usage; exit 0 ;; - --) PYTEST_ARGS="${@:2}"; break ;; + -l|--lint) RUN_ALL=false; RUN_LINT=true ;; + -u|--unit) RUN_ALL=false; RUN_UNIT=true ;; + -i|--integ) RUN_ALL=false; RUN_INTEG=true ;; + -a|--abao) RUN_ALL=false; RUN_ABAO=true ;; + -h|--help) usage; exit 0 ;; + --) PYTEST_ARGS="${@:2}"; break ;; *) echo "Invalid argument: $1" >&2; usage; exit 1 ;; esac shift done - if ! (${RUN_LINT} && ${RUN_UNIT} && ${RUN_INTEG} && ${RUN_ABAO}); then - # Skip coverage report if any tests are skipped - RUN_REPORT=false + if ${RUN_ALL}; then + # No filtering options used, run everything by default + RUN_LINT=true + RUN_UNIT=true + RUN_INTEG=true + RUN_ABAO=true + elif ${RUN_LINT} && ${RUN_UNIT} && ${RUN_INTEG} && ${RUN_ABAO}; then + # All filtering options were used, the same as none + RUN_ALL=true fi trap clean_up EXIT @@ -164,7 +171,7 @@ function clean_up () { wait 2> /dev/null fi - if ${RUN_REPORT} && [[ "${TEST_RESULT_CODE}" == "0" ]]; then + if ${RUN_ALL} && [[ "${TEST_RESULT_CODE}" == "0" ]]; then echo echo "UNIT TEST COVERAGE:" coverage report --skip-covered