skipWithoutSudo() runs "sudo -n /bin/true" when the decorator is
evaluated, i.e. at module import time. If sudo is not installed (as in
the centos and opensuse CI containers), subprocess.run() raises
FileNotFoundError and the whole test module fails to load, including
the asset precache step. Skip the test instead.

Fixes: ac84b9ec9604 ("tests/functional: add skipWithoutSudo() decorator")
Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
---
 tests/functional/qemu_test/decorators.py | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/tests/functional/qemu_test/decorators.py 
b/tests/functional/qemu_test/decorators.py
index aa135acc785..9df8d1e3000 100644
--- a/tests/functional/qemu_test/decorators.py
+++ b/tests/functional/qemu_test/decorators.py
@@ -184,12 +184,15 @@ def skipLockedMemoryTest(locked_memory):
 sudo command is not available.
 '''
 def skipWithoutSudo():
-    proc = subprocess.run(["sudo", "-n", "/bin/true"],
-                          stdin=subprocess.PIPE,
-                          stdout=subprocess.PIPE,
-                          stderr=subprocess.STDOUT,
-                          universal_newlines=True,
-                          check=False)
+    try:
+        proc = subprocess.run(["sudo", "-n", "/bin/true"],
+                              stdin=subprocess.PIPE,
+                              stdout=subprocess.PIPE,
+                              stderr=subprocess.STDOUT,
+                              universal_newlines=True,
+                              check=False)
+    except OSError as e:
+        return skipUnless(False, f'requires sudo: {e}')
 
     return skipUnless(proc.returncode == 0,
                       f'requires password-less sudo access: {proc.stdout}')
-- 
2.43.0


Reply via email to