#!/bin/bash

# Run the unit tests of one upstream sub-project against the installed
# binary package. Usage: run-unittests <subdir> [pytest options]
#
# The tests are copied out of the source tree, so they import the installed
# modules and do not pick up the repository-root pytest.ini.

set -e -u

SUBDIR="$1"
shift
PKG_NAME=$(basename "${SUBDIR}")

mkdir -p "${AUTOPKGTEST_TMP}/${PKG_NAME}"
cp -a "${SUBDIR}"/tests "${AUTOPKGTEST_TMP}/${PKG_NAME}"

for py3vers in $(py3versions -s); do
    echo
    echo "***************************"
    echo "*** (python3-${PKG_NAME})"
    echo "*** Testing with ${py3vers}"
    echo "***************************"
    echo
    cd "${AUTOPKGTEST_TMP}/${PKG_NAME}" && \
        "${py3vers}" -m pytest tests "$@" && \
        rm -rf .pytest_cache || exit 1
done

echo

exit 0
