diff --git a/tests/python/utils.py b/tests/python/utils.py index b1a7d263801c..40e7b157dc33 100644 --- a/tests/python/utils.py +++ b/tests/python/utils.py @@ -2,6 +2,7 @@ from distutils.spawn import find_executable import traceback import distutils.version +import shutil import logging, os, sys @@ -51,6 +52,23 @@ def wrapper(*args, **kwargs): return wrapper return decorator +# This is a decorator that will skip tests if any binary in the list is not in PATH. +def skipUnlessHasBinaries(binaries, message): + def decorator(func): + def wrapper(self, *args, **kwargs): + missing = [] + for binary in binaries: + if shutil.which(binary) is None: + missing.append(binary) + + if len(missing): + missing_binaries = ", ".join(missing) + self.skipTest(f"Missing binaries: {missing_binaries}. {message}") + else: + func(self, *args, **kwargs) + return wrapper + return decorator + class NSPopenWithCheck(NSPopen): """ A wrapper for NSPopen that additionally checks if the program