From 33517beb4096193d4447803896f31edda686af78 Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Tue, 24 Apr 2018 14:14:29 -0400 Subject: [PATCH] selftests/unit/test_utils_process.py: skip test if sudo is not available test_run_sudo() actually needs sudo, because it attempts to run it. Let's check for the file at the usual location, and skip the test unless it exists. ERROR: test_run_sudo (selftests.unit.test_utils_process.TestProcessRun) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/travis/virtualenv/python2.7_with_system_site_packages/local/lib/python2.7/site-packages/mock/mock.py", line 1305, in patched return func(*args, **keywargs) File "selftests/unit/test_utils_process.py", line 180, in test_run_sudo p = process.run(cmd='ls -l', sudo=True, ignore_status=True) File "avocado/utils/process.py", line 1272, in run cmd_result = sp.run(timeout=timeout) File "avocado/utils/process.py", line 781, in run self._init_subprocess() File "avocado/utils/process.py", line 571, in _init_subprocess raise details OSError: [Errno 2] No such file or directory (/bin/sudo -n ls -l) Signed-off-by: Cleber Rosa --- selftests/unit/test_utils_process.py | 1 + 1 file changed, 1 insertion(+) diff --git a/selftests/unit/test_utils_process.py b/selftests/unit/test_utils_process.py index c79ab7fc..add9a471 100644 --- a/selftests/unit/test_utils_process.py +++ b/selftests/unit/test_utils_process.py @@ -172,6 +172,7 @@ class TestProcessRun(unittest.TestCase): p = process.run(cmd='ls -l', ignore_status=True) self.assertEqual(p.command, expected_command) + @unittest.skipUnless(os.path.exists('/bin/sudo')) @mock.patch.object(path, 'find_command', mock.Mock(return_value='/bin/sudo')) @mock.patch.object(os, 'getuid', mock.Mock(return_value=1000)) -- GitLab