#!/bin/bash

set -e -u

cp -a docs tests "${AUTOPKGTEST_TMP}"

PYTEST_OPTIONS="\
 --ignore=${AUTOPKGTEST_TMP}/docs/examples/testing/test_subprocess_sse.py \
 --ignore=${AUTOPKGTEST_TMP}/tests/examples/test_contrib/test_sqlalchemy/plugins/test_example_apps.py \
 --ignore=${AUTOPKGTEST_TMP}/tests/unit/test_channels/test_backends.py \
 --ignore=${AUTOPKGTEST_TMP}/tests/unit/test_channels/test_plugin.py \
 --ignore=${AUTOPKGTEST_TMP}/tests/unit/test_cli/test_schema_commands.py \
 --ignore=${AUTOPKGTEST_TMP}/tests/unit/test_contrib/test_opentelemetry.py \
 --ignore=${AUTOPKGTEST_TMP}/tests/unit/test_file_system.py \
 --ignore=${AUTOPKGTEST_TMP}/tests/unit/test_kwargs/test_validations.py \
 --ignore=${AUTOPKGTEST_TMP}/tests/unit/test_middleware/test_rate_limit_middleware.py \
 --ignore=${AUTOPKGTEST_TMP}/tests/unit/test_openapi \
 --ignore=${AUTOPKGTEST_TMP}/tests/unit/test_stores.py \
 --ignore=${AUTOPKGTEST_TMP}/tests/unit/test_testing/test_sub_client/test_subprocess_client.py \
 --ignore=${AUTOPKGTEST_TMP}/tests/unit/test_testing/test_test_client.py \
"

for py3vers in $(py3versions -s); do
    echo
    echo "***************************"
    echo "*** Testing with ${py3vers}"
    echo "***************************"
    echo
    cd ${AUTOPKGTEST_TMP} && \
        echo -e "Content of current working folder:\n" && \
        pwd && \
        ls -la && \
        echo -e "Running tests...\n" && \
        PYTHONPATH=. "${py3vers}" -m pytest $PYTEST_OPTIONS -k \
            "not test_backlog \
         and not test_file_adapter_info_handles_permission_exception \
         and not test_file_adapter_open_handles_permission_exception \
         and not test_jwt_auth \
         and not test_jwt_cookie_auth \
         and not test_prometheus_exporter_metrics_with_http \
         and not test_qsize \
         and not test_request_body \
         and not test_request_body_logging_middleware \
         and not test_request_stream \
         and not test_sqlalchemy_declarative_models \
         and not test_tutorial_example_apps.py \
         and not test_warn_default_inside_kwarg_definition_and_default_empty \
         and not test_with_portal \
         and not test_with_stores \
         " tests && \
        rm -rf .pytest_cache || exit 1
done

echo

exit 0


