]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
tests/functional: Add decorator to skip test on missing env vars
authorGustavo Romero <gustavo.romero@linaro.org>
Fri, 3 Oct 2025 14:18:18 +0000 (14:18 +0000)
committerAlex Bennée <alex.bennee@linaro.org>
Tue, 7 Oct 2025 06:33:40 +0000 (07:33 +0100)
Add a decorator to skip tests on missing env variable(s). Multiple
variable names can be provided and if one or more of them are not set in
the test environment the test is skipped and the missing vars are
printed out.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
Message-ID: <20251003141820.85278-8-gustavo.romero@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
tests/functional/qemu_test/__init__.py
tests/functional/qemu_test/decorators.py

index 60d19891bfc314db766bdd2f7258c4a3996830eb..320193591b28f4e547755230641f82ff8a1ca8c5 100644 (file)
@@ -15,7 +15,8 @@ from .testcase import QemuBaseTest, QemuUserTest, QemuSystemTest
 from .linuxkernel import LinuxKernelTest
 from .decorators import skipIfMissingCommands, skipIfNotMachine, \
     skipFlakyTest, skipUntrustedTest, skipBigDataTest, skipSlowTest, \
-    skipIfMissingImports, skipIfOperatingSystem, skipLockedMemoryTest
+    skipIfMissingImports, skipIfOperatingSystem, skipLockedMemoryTest, \
+    skipIfMissingEnv
 from .archive import archive_extract
 from .uncompress import uncompress
 from .gdb import GDB
index c0d1567b1422cd54fd752acf9724568b5bb51983..b2392958041fb1f453d5f61ba4c8c7a0bc5c542a 100644 (file)
@@ -11,6 +11,24 @@ from unittest import skipIf, skipUnless
 from .cmd import which
 
 '''
+Decorator to skip execution of a test if the provided
+environment variables are not set.
+Example:
+
+  @skipIfMissingEnv("QEMU_ENV_VAR0", "QEMU_ENV_VAR1")
+'''
+def skipIfMissingEnv(*vars_):
+    missing_vars = []
+    for var in vars_:
+        if os.getenv(var) == None:
+            missing_vars.append(var)
+
+    has_vars = True if len(missing_vars) == 0 else False
+
+    return skipUnless(has_vars, f"Missing env var(s): {', '.join(missing_vars)}")
+
+'''
+
 Decorator to skip execution of a test if the list
 of command binaries is not available in $PATH.
 Example: