From c2dee5e6e1462ae55eb8c077fef3fd29810cc1c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Tue, 27 Oct 2026 08:15:40 +0100 Subject: [PATCH] test(spanner): fall back to local Python version for mockserver tests Fall back to the local Python version when running mockserver tests to prevent CI failures due to new Python versions, or local build failures due to missing Python versions locally. The mockserver tests do not really care about which Python version is being used, as long as it is one that is supported by the Spanner client. --- .../client-post-processing/spanner-integration.yaml | 13 ++++++++++++- packages/google-cloud-spanner/noxfile.py | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.librarian/generator-input/client-post-processing/spanner-integration.yaml b/.librarian/generator-input/client-post-processing/spanner-integration.yaml index 7b1b268ed15a..90e6a312e3b5 100644 --- a/.librarian/generator-input/client-post-processing/spanner-integration.yaml +++ b/.librarian/generator-input/client-post-processing/spanner-integration.yaml @@ -659,6 +659,7 @@ replacements: import pathlib import re import shutil + import sys import warnings from typing import Dict, List @@ -669,7 +670,17 @@ replacements: DEFAULT_PYTHON_VERSION = "3.14" - DEFAULT_MOCK_SERVER_TESTS_PYTHON_VERSION = "3.12" + # Default to Python 3.12 for local development if available. If Python 3.12 is + # not installed (such as in CI environments where a different Python version + # is provisioned), fall back to the currently running Python interpreter to + # avoid InterpreterNotFound errors. Can also be overridden via the + # MOCK_SERVER_TESTS_PYTHON_VERSION environment variable. + DEFAULT_MOCK_SERVER_TESTS_PYTHON_VERSION = os.environ.get( + "MOCK_SERVER_TESTS_PYTHON_VERSION", + "3.12" + if shutil.which("python3.12") + else f"{sys.version_info.major}.{sys.version_info.minor}", + ) SYSTEM_TEST_PYTHON_VERSIONS: List[str] = ["3.12"] ALL_PYTHON: List[str] = [ diff --git a/packages/google-cloud-spanner/noxfile.py b/packages/google-cloud-spanner/noxfile.py index e14de4a0bc44..6ea3054a2277 100644 --- a/packages/google-cloud-spanner/noxfile.py +++ b/packages/google-cloud-spanner/noxfile.py @@ -17,6 +17,7 @@ import pathlib import re import shutil +import sys import warnings from typing import Dict, List @@ -27,7 +28,17 @@ DEFAULT_PYTHON_VERSION = "3.14" -DEFAULT_MOCK_SERVER_TESTS_PYTHON_VERSION = "3.12" +# Default to Python 3.12 for local development if available. If Python 3.12 is +# not installed (such as in CI environments where a different Python version +# is provisioned), fall back to the currently running Python interpreter to +# avoid InterpreterNotFound errors. Can also be overridden via the +# MOCK_SERVER_TESTS_PYTHON_VERSION environment variable. +DEFAULT_MOCK_SERVER_TESTS_PYTHON_VERSION = os.environ.get( + "MOCK_SERVER_TESTS_PYTHON_VERSION", + "3.12" + if shutil.which("python3.12") + else f"{sys.version_info.major}.{sys.version_info.minor}", +) SYSTEM_TEST_PYTHON_VERSIONS: List[str] = ["3.12"] ALL_PYTHON: List[str] = [