diff options
-rw-r--r-- | framework/tests/base_tests.py | 2 | ||||
-rw-r--r-- | framework/tests/utils.py | 24 |
2 files changed, 20 insertions, 6 deletions
diff --git a/framework/tests/base_tests.py b/framework/tests/base_tests.py index a9e0e88c4..7b2920de9 100644 --- a/framework/tests/base_tests.py +++ b/framework/tests/base_tests.py @@ -57,7 +57,7 @@ def test_run_return_early(): def test_timeout(): """test.base.Test.run(): kills tests that exceed timeout when set""" - utils.binary_check('sleep') + utils.binary_check('sleep', 1) def helper(): if (test.result['returncode'] == 0): diff --git a/framework/tests/utils.py b/framework/tests/utils.py index 55d2b6ecf..58f8c2f27 100644 --- a/framework/tests/utils.py +++ b/framework/tests/utils.py @@ -32,6 +32,7 @@ import shutil import tempfile as tempfile_ import functools import subprocess +import errno from contextlib import contextmanager try: @@ -276,13 +277,26 @@ def privileged_test(func): return func -def binary_check(bin_): - """Check for the existance of a binary or raise SkipTest.""" +def binary_check(bin_, errno_=None): + """Check for the existance of a binary or raise SkipTest. + + If an errno_ is provided then a skip test will be raised unless the error + number provided is raised, or no error is raised. + + """ with open(os.devnull, 'w') as null: try: - subprocess.check_call(['which', bin_], stdout=null, stderr=null) - except subprocess.CalledProcessError: - raise SkipTest('Binary {} not available'.format(bin_)) + subprocess.check_call([bin_], stdout=null, stderr=null) + except OSError as e: + if e.errno == errno.ENOENT: + raise SkipTest('Binary {} not available'.format(bin_)) + except subprocess.CalledProcessError as e: + if errno_ is not None and e.returncode == errno_: + pass + else: + raise SkipTest( + 'Binary provided bad returncode of {} (wanted {})'.format( + e.returncode, errno_)) def platform_check(plat): |