aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Huth <thuth@redhat.com>2025-01-22 14:43:14 +0100
committerThomas Huth <thuth@redhat.com>2025-01-30 10:30:36 +0100
commit257de641e091f4f5063298b9d717f3f15f8917f2 (patch)
tree7cdc5e36932d11f34cc208541c8af191d142c6f2
parentaca2c48e4d26426c14499fd3d8a2e333ac57d267 (diff)
downloadqemu-257de641e091f4f5063298b9d717f3f15f8917f2.zip
qemu-257de641e091f4f5063298b9d717f3f15f8917f2.tar.gz
qemu-257de641e091f4f5063298b9d717f3f15f8917f2.tar.bz2
tests/functional: Fix broken decorators with lamda functions
The decorators that use a lambda function are currently broken and do not properly skip the test if the condition is not met. Using "return skipUnless(lambda: ...)" does not work as expected. To fix it, rewrite the decorators without lambda, it's simpler that way anyway. Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20250122134315.1448794-3-thuth@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
-rw-r--r--tests/functional/qemu_test/decorators.py44
1 files changed, 21 insertions, 23 deletions
diff --git a/tests/functional/qemu_test/decorators.py b/tests/functional/qemu_test/decorators.py
index 08f58f6..3d9c02f 100644
--- a/tests/functional/qemu_test/decorators.py
+++ b/tests/functional/qemu_test/decorators.py
@@ -17,15 +17,14 @@ Example:
@skipIfMissingCommands("mkisofs", "losetup")
'''
def skipIfMissingCommands(*args):
- def has_cmds(cmdlist):
- for cmd in cmdlist:
- if not which(cmd):
- return False
- return True
-
- return skipUnless(lambda: has_cmds(args),
- 'required command(s) "%s" not installed' %
- ", ".join(args))
+ has_cmds = True
+ for cmd in args:
+ if not which(cmd):
+ has_cmds = False
+ break
+
+ return skipUnless(has_cmds, 'required command(s) "%s" not installed' %
+ ", ".join(args))
'''
Decorator to skip execution of a test if the current
@@ -36,9 +35,9 @@ Example
@skipIfNotMachine("x86_64", "aarch64")
'''
def skipIfNotMachine(*args):
- return skipUnless(lambda: platform.machine() in args,
- 'not running on one of the required machine(s) "%s"' %
- ", ".join(args))
+ return skipUnless(platform.machine() in args,
+ 'not running on one of the required machine(s) "%s"' %
+ ", ".join(args))
'''
Decorator to skip execution of flaky tests, unless
@@ -95,14 +94,13 @@ Example:
@skipIfMissingImports("numpy", "cv2")
'''
def skipIfMissingImports(*args):
- def has_imports(importlist):
- for impname in importlist:
- try:
- importlib.import_module(impname)
- except ImportError:
- return False
- return True
-
- return skipUnless(lambda: has_imports(args),
- 'required import(s) "%s" not installed' %
- ", ".join(args))
+ has_imports = True
+ for impname in args:
+ try:
+ importlib.import_module(impname)
+ except ImportError:
+ has_imports = False
+ break
+
+ return skipUnless(has_imports, 'required import(s) "%s" not installed' %
+ ", ".join(args))