1#!/usr/bin/env bash 2# SPDX-License-Identifier: MIT 3# © Collabora Limited 4# Author: Guilherme Gallo <guilherme.gallo@collabora.com> 5 6# This script runs unit/integration tests related with LAVA CI tools 7# shellcheck disable=SC1091 # The relative paths in this file only become valid at runtime. 8# shellcheck disable=SC2086 # quoting PYTEST_VERBOSE makes us pass an empty path 9 10set -eu 11 12PYTHON_BIN="python3.11" 13 14if [ -z "${SCRIPTS_DIR:-}" ]; then 15 SCRIPTS_DIR="$(dirname "${0}")" 16fi 17 18if [ -z "${CI_JOB_STARTED_AT:-}" ]; then 19 CI_JOB_STARTED_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ) # isoformat 20fi 21 22source "${SCRIPTS_DIR}/setup-test-env.sh" 23 24if [ -z "${CI_PROJECT_DIR:-}" ]; then 25 CI_PROJECT_DIR="$(dirname "${0}")/../" 26fi 27 28if [ -z "${CI_JOB_TIMEOUT:-}" ]; then 29 # Export this default value, 1 hour in seconds, to test the lava job submitter 30 export CI_JOB_TIMEOUT=3600 31fi 32 33# If running outside of the debian/x86_64_pyutils container, 34# run in a virtual environment for isolation 35# e.g. USE_VENV=true ./.gitlab-ci/run-pytest.sh 36if [ "${USE_VENV:-}" == true ]; then 37 echo "Setting up virtual environment for local testing." 38 MESA_PYTEST_VENV="${CI_PROJECT_DIR}/.venv-pytest" 39 ${PYTHON_BIN} -m venv "${MESA_PYTEST_VENV}" 40 source "${MESA_PYTEST_VENV}"/bin/activate 41 ${PYTHON_BIN} -m pip install --break-system-packages -r "${CI_PROJECT_DIR}/bin/ci/test/requirements.txt" 42fi 43 44LIB_TEST_DIR=${CI_PROJECT_DIR}/.gitlab-ci/tests 45SCRIPT_TEST_DIR=${CI_PROJECT_DIR}/bin/ci 46 47uncollapsed_section_start pytest "Running pytest" 48 49PYTHONPATH="${LIB_TEST_DIR}:${SCRIPT_TEST_DIR}:${PYTHONPATH:-}" ${PYTHON_BIN} -m \ 50 pytest "${LIB_TEST_DIR}" "${SCRIPT_TEST_DIR}" \ 51 -W ignore::DeprecationWarning \ 52 --junitxml=artifacts/ci_scripts_report.xml \ 53 -m 'not slow' \ 54 ${PYTEST_VERBOSE:-} 55 56section_end pytest 57 58section_start flake8 "flake8" 59${PYTHON_BIN} -m flake8 \ 60--config "${CI_PROJECT_DIR}/.gitlab-ci/.flake8" \ 61"${LIB_TEST_DIR}" "${SCRIPT_TEST_DIR}" 62section_end flake8 63