diff --git a/run-tests.sh b/run-tests.sh index a7832d70a8fbf39741b13e5fb31b1c945f877dba..98f256b79f92db0370f67dc4fc9386205257bde8 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -1,19 +1,50 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash # -*- coding: utf-8 -*- # -# Copyright (C) 2020-2022 TU Wien. +# Copyright (C) 2020-2024 TU Wien. # -# Invenio-Utilities-TUW is free software; you can redistribute it and/or -# modify it under the terms of the MIT License; see LICENSE file for more -# details. +# Invenio-Theme-TUW is free software; you can redistribute it and/or modify +# it under the terms of the MIT License; see LICENSE file for more details. +# Quit on errors +set -o errexit -# TODO: Pass the services required by your module to the -# docker-services-cli e.g. `docker-services-cli up es postgresql redis` -# remove docker-services-cli if you don't need any of the services. -docker-services-cli up && \ -python -m check_manifest --ignore ".travis-*" && \ -python -m pytest +# Quit on unbound symbols +set -o nounset + +# Define function for bringing down services +cleanup() { + eval "$(docker-services-cli down --env)" +} + +# Check for arguments +# Note: "-k" would clash with "pytest" +keep_services=0 +pytest_args=() +for arg in $@; do + # from the CLI args, filter out some known values and forward the rest to "pytest" + # note: we don't use "getopts" here b/c of some limitations (e.g. long options), + # which means that we can't combine short options (e.g. "./run-tests -Kk pattern") + case ${arg} in + -K|--keep-services) + keep_services=1 + ;; + *) + pytest_args+=( "${arg}" ) + ;; + esac +done + +if [[ ${keep_services} -eq 0 ]]; then + trap cleanup EXIT +fi + +export LC_TIME=en_US.UTF-8 +python -m check_manifest +eval "$(docker-services-cli up --db "${DB:-postgresql}" --search "${SEARCH:-opensearch}" --mq "${MQ:-rabbitmq}" --cache "${CACHE:-redis}" --env)" + +# Note: expansion of pytest_args looks like below to not cause an unbound +# variable error when 1) "nounset" and 2) the array is empty. +python -m pytest ${pytest_args[@]+"${pytest_args[@]}"} tests_exit_code=$? -docker-services-cli down exit "$tests_exit_code" diff --git a/tests/conftest.py b/tests/conftest.py index 810a24f679074b1d20abfc9cd3c60585a7d2ce0d..01166cfc175eb92321d99ebd05ce531480e22226 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,7 +20,6 @@ from flask import Flask from invenio_i18n import Babel from invenio_utilities_tuw import InvenioUtilitiesTUW -from invenio_utilities_tuw.views import blueprint @pytest.fixture(scope="module")