Files
kevinveenbirkenbachandClaude Opus 5.5 21e05b9d42 feat(env): switch the GPU-only tests with INFINITO_TEST_GPU
The two tests that only answer on a GPU host, the logout catalogue translation check and the complete-catalogs integration test, were gated on accelerated() alone: a contributor with an NVIDIA runtime had no way to keep them out of a local gate while the GPU translation run is paused, so every gate on such a host stayed red on them.

INFINITO_TEST_GPU is a new env key. Its handler derives the default from INFINITO_GPU_COUNT: true where the compose services reserve a GPU, false for 0 or none. custom.env is applied after every handler, so `INFINITO_TEST_GPU=false` there switches the tests off on a GPU host; an exported value wins as well. tests/utils/gpu.py reads the flag for both tests, fails on any value other than true or false, and falls back to the same GPU detection only where no .env is loaded, such as a direct pytest run.

The handler joins gpu_count in utils/env/handlers/infinito/gpu/ (count.py, only_tests.py), because two handlers sharing the gpu prefix are a folder by the prefix-grouping lint. The new module avoids a test* name so unittest discovery never collects it. customize.md lists the key among the common overrides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 11:50:26 +01:00

28 lines
798 B
Python

"""Whether the GPU-only tests run on this host."""
from __future__ import annotations
import os
from utils.i18n.libretranslate import accelerated
FLAG = "INFINITO_TEST_GPU"
def gpu_tests_enabled() -> bool:
"""Read ``INFINITO_TEST_GPU``, which ``make dotenv`` derives from the GPU count and ``custom.env`` overrides.
Returns:
The flag. Where the env was not loaded, the same derivation the
handler uses: whether Docker can hand a GPU to a container.
Raises:
ValueError: the flag is neither ``true`` nor ``false``.
"""
raw = (os.environ.get(FLAG) or "").strip().lower()
if not raw:
return accelerated()
if raw not in ("true", "false"):
raise ValueError(f"{FLAG} must be true or false, got {raw!r}")
return raw == "true"