run_python_tests•1.8 kB
#!/usr/bin/env bash
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
# Run tests for all supported Python versions
set -euo pipefail
TOP_DIR=$(git rev-parse --show-toplevel)
PY_DIR="${TOP_DIR}/py"
PYTHON_VERSIONS=(
  #"pypy3.10" # TODO: Fix numpy build failures.
  #"pypy3.11" # TODO: Fix numpy build failures.
  "python3.10"
  "python3.11"
  "python3.12"
  "python3.13"
  #"pypy3.12" # TODO: Enable when it is released.
  # TODO: Wait for https://github.com/PyO3/pyo3/issues/5000 to be fixed.
  #"python3.14" # Next version to catch breakages early.
)
# WORKAROUND:
#
# error: the configured Python interpreter version (3.14) is newer than PyO3's
# maximum supported version (3.13)
#
#  = help: please check if an updated version of PyO3 is available. Current
#  version: 0.24.0
#  = help: set PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 to suppress this check and
#  build anyway using the stable ABI
export PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1
PYTEST_ARGS=(
  "-v"
  #"-vv"
  #"--log-level=DEBUG"
)
for VERSION in "${PYTHON_VERSIONS[@]}"; do
  echo "Running tests with Python ${VERSION}..."
  uv run \
    --python "${VERSION}" \
    --active \
    --isolated \
    --directory "${PY_DIR}" \
    pytest "${PYTEST_ARGS[@]}" .
done