mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-09-08 16:07:39 -06:00
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>
This commit is contained in:
parent
aca2c48e4d
commit
257de641e0
1 changed files with 19 additions and 21 deletions
|
@ -17,15 +17,14 @@ Example:
|
||||||
@skipIfMissingCommands("mkisofs", "losetup")
|
@skipIfMissingCommands("mkisofs", "losetup")
|
||||||
'''
|
'''
|
||||||
def skipIfMissingCommands(*args):
|
def skipIfMissingCommands(*args):
|
||||||
def has_cmds(cmdlist):
|
has_cmds = True
|
||||||
for cmd in cmdlist:
|
for cmd in args:
|
||||||
if not which(cmd):
|
if not which(cmd):
|
||||||
return False
|
has_cmds = False
|
||||||
return True
|
break
|
||||||
|
|
||||||
return skipUnless(lambda: has_cmds(args),
|
return skipUnless(has_cmds, 'required command(s) "%s" not installed' %
|
||||||
'required command(s) "%s" not installed' %
|
", ".join(args))
|
||||||
", ".join(args))
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Decorator to skip execution of a test if the current
|
Decorator to skip execution of a test if the current
|
||||||
|
@ -36,9 +35,9 @@ Example
|
||||||
@skipIfNotMachine("x86_64", "aarch64")
|
@skipIfNotMachine("x86_64", "aarch64")
|
||||||
'''
|
'''
|
||||||
def skipIfNotMachine(*args):
|
def skipIfNotMachine(*args):
|
||||||
return skipUnless(lambda: platform.machine() in args,
|
return skipUnless(platform.machine() in args,
|
||||||
'not running on one of the required machine(s) "%s"' %
|
'not running on one of the required machine(s) "%s"' %
|
||||||
", ".join(args))
|
", ".join(args))
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Decorator to skip execution of flaky tests, unless
|
Decorator to skip execution of flaky tests, unless
|
||||||
|
@ -95,14 +94,13 @@ Example:
|
||||||
@skipIfMissingImports("numpy", "cv2")
|
@skipIfMissingImports("numpy", "cv2")
|
||||||
'''
|
'''
|
||||||
def skipIfMissingImports(*args):
|
def skipIfMissingImports(*args):
|
||||||
def has_imports(importlist):
|
has_imports = True
|
||||||
for impname in importlist:
|
for impname in args:
|
||||||
try:
|
try:
|
||||||
importlib.import_module(impname)
|
importlib.import_module(impname)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
return False
|
has_imports = False
|
||||||
return True
|
break
|
||||||
|
|
||||||
return skipUnless(lambda: has_imports(args),
|
return skipUnless(has_imports, 'required import(s) "%s" not installed' %
|
||||||
'required import(s) "%s" not installed' %
|
", ".join(args))
|
||||||
", ".join(args))
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue