From 7dc4b8106a71ea11a9a43fe25899be0a73458b5f Mon Sep 17 00:00:00 2001 From: Maximilian Moser <maximilian.moser@tuwien.ac.at> Date: Thu, 19 Sep 2024 18:38:11 +0200 Subject: [PATCH] Update run-tests.sh --- run-tests.sh | 55 ++++++++++++++++++++++++++++++++++++----------- tests/conftest.py | 1 - 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/run-tests.sh b/run-tests.sh index a7832d7..98f256b 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 810a24f..01166cf 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") -- GitLab