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 | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/tests/functional/qemu_test/decorators.py
b/tests/functional/qemu_test/decorators.py
index aa135acc785..b044f96c941 100644
--- a/tests/functional/qemu_test/decorators.py
+++ b/tests/functional/qemu_test/decorators.py
@@ -7,7 +7,7 @@
import platform
import resource
import subprocess
-from unittest import skipIf, skipUnless
+from unittest import skip, skipIf, skipUnless
from .cmd import which
@@ -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 skip(f'requires sudo: {e}')
return skipUnless(proc.returncode == 0,
f'requires password-less sudo access: {proc.stdout}')
--
2.43.0