diff --git a/testsuite/README.md b/testsuite/README.md index 5a212dbe0..28b3a50fb 100644 --- a/testsuite/README.md +++ b/testsuite/README.md @@ -36,8 +36,28 @@ $ ./run.py ``` # Creating tests -All tests are based on running a Python script. There are three test drivers: +All tests are based on running a Python script. There are these test drivers: - `python-script`: run in host in both sandboxed and shared build mode. - The build mode can be narrowed down with the `build_mode` attribute. - `docker-wrapper`: run in a pristine docker Ubuntu image in shared build mode. + +# Environment variables +The following variables can be used to modify test/testsuite behavior. + +For `ALIRE_DISABLE_*` variables, their mere existence activates their function, +no matter their value, or lack of one. + +- `ALIRE_DISABLE_DISTRO`: when defined, `alr` will be configured + to not detect the system distribution and fall back to unknown distribution. + +- `ALIRE_DISABLE_DOCKER`: when defined, `alr` will skip tests that + require Docker (which are enabled by default if Docker is detected). + +- `ALIRE_DISABLE_NETWORK_TESTS`: when defined, tests that + require non-local network use will be skipped. + +Example disabling Docker tests for a single run on Bash: +```Bash +$ ALIRE_DISABLE_DOCKER= ./run.sh +``` diff --git a/testsuite/drivers/alr.py b/testsuite/drivers/alr.py index 856a328b2..5d16f0dc4 100644 --- a/testsuite/drivers/alr.py +++ b/testsuite/drivers/alr.py @@ -72,9 +72,8 @@ def prepare_env(config_dir, env): # If distro detection is disabled via environment, configure so in alr if "ALIRE_DISABLE_DISTRO" in env: - if env["ALIRE_DISABLE_DISTRO"] == "true": - run_alr("-c", config_dir, "config", "--global", - "--set", "distribution.disable_detection", "true") + run_alr("-c", config_dir, "config", "--global", + "--set", "distribution.disable_detection", "true") def run_alr(*args, **kwargs): diff --git a/testsuite/drivers/driver/docker_nested.py b/testsuite/drivers/driver/docker_nested.py index 885850ee1..647ab6507 100644 --- a/testsuite/drivers/driver/docker_nested.py +++ b/testsuite/drivers/driver/docker_nested.py @@ -10,6 +10,7 @@ from drivers import alr from drivers.alr import run_alr +from drivers.helpers import MODIFIERS def main(): @@ -34,6 +35,10 @@ def main(): # Set up the environment + # Copy any received modifiers + for modifier in [m for m in MODIFIERS if m in test_env]: + os.environ[modifier] = test_env[modifier] + # alr path os.environ["ALR_PATH"] = "/usr/bin/alr" # Must match docker volume mount diff --git a/testsuite/drivers/driver/docker_wrapper.py b/testsuite/drivers/driver/docker_wrapper.py index 7b73ebb10..5d974a728 100644 --- a/testsuite/drivers/driver/docker_wrapper.py +++ b/testsuite/drivers/driver/docker_wrapper.py @@ -5,14 +5,14 @@ from importlib import import_module from typing import Tuple -from drivers.helpers import FileLock, on_linux +from drivers.helpers import FileLock, on_linux, MODIFIERS from e3.testsuite.driver.classic import (ClassicTestDriver, TestAbortWithFailure, TestSkip) DOCKERFILE = "Dockerfile" TAG = "alire_testsuite" -ENV_FLAG = "ALIRE_DOCKER_ENABLED" # Set to "False" to disable docker tests +ENV_FLAG = "ALIRE_DISABLE_DOCKER" # Export it to disable docker tests LABEL_HASH = "hash" @@ -22,7 +22,7 @@ def is_docker_available() -> bool: return False # Detect explicitly disabled - if os.environ.get(ENV_FLAG, "True").lower() in ["0", "false"]: + if ENV_FLAG in os.environ: return False # Detect python library @@ -102,6 +102,11 @@ def run(self): build_image() + # Augment the test environment with local modifiers that could + # impact the wrapped test, if defined + for modifier in [m for m in MODIFIERS if m in os.environ]: + self.test_env[modifier] = os.environ[modifier] + # Run our things try: container = get_client().containers.run( @@ -137,6 +142,10 @@ def run(self): # Check that the test succeeded inside the docker container out_lines = output.splitlines() - if not out_lines or out_lines[-1] != 'SUCCESS': - self.result.log += f'missing SUCCESS output line:\n{output}' + if out_lines and out_lines[-1] == 'SUCCESS': + pass + elif out_lines and (reason := out_lines[-1]).startswith('SKIP:'): + raise TestSkip(reason.split(":")[-1].strip()) + else: + self.result.log += 'missing SUCCESS output line' raise TestAbortWithFailure('missing SUCCESS output line') \ No newline at end of file diff --git a/testsuite/drivers/helpers.py b/testsuite/drivers/helpers.py index 6b3c04bb6..9d0b2e64b 100644 --- a/testsuite/drivers/helpers.py +++ b/testsuite/drivers/helpers.py @@ -11,6 +11,12 @@ from subprocess import run from zipfile import ZipFile +# Environment variables that can be used to modify the testsuite behavior +MODIFIERS : list = [ + 'ALIRE_DISABLE_DISTRO' + , 'ALIRE_DISABLE_DOCKER' + , 'ALIRE_DISABLE_NETWORK_TESTS' +] # Return the entries (sorted) under a given folder, both folders and files # Optionally, return only those matching regex. Uses '/' always as separator. @@ -77,7 +83,7 @@ def on_windows(): def distribution(): - if os.environ.get('ALIRE_DISABLE_DISTRO') == 'true': + if 'ALIRE_DISABLE_DISTRO' in os.environ: return 'DISTRO_UNKNOWN' known_distro = ["debian", "ubuntu", "msys2", "arch", "rhel", "centos", "fedora"]