def skip_if_lib_missing(libname, text=None): """ pytest decorator to evaluate the required shared lib. :param libname: Name of the required library. :param text: Text to put into the reason message (defaults to 'lib%s.so' % libname) :return: pytest decorator with a reason. """ soname = ctypes.util.find_library(libname) if not text: text = "lib%s.so" % libname # Return pytest decorator. return skipif(not (soname and ctypes.CDLL(soname)), reason="required %s missing" % text)