Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:
Here is the implementation of the second option: def requires_hashdigest(digestname, openssl=None, usedforsecurity=True): def decorator(func): if isinstance(func, type): setUpClass = func.__dict__.get('setUpClass') if setUpClass is None: def setUpClass(cls): super(func, cls).setUpClass() setUpClass.__qualname__ = func.__qualname__ + '.setUpClass' setUpClass.__module__ = func.__module__ else: setUpClass = setUpClass.__func__ setUpClass = classmethod(decorator(setUpClass)) func.setUpClass = setUpClass return func @functools.wraps(func) def wrapper(*args, **kwargs): try: if openssl and _hashlib is not None: _hashlib.new(digestname, usedforsecurity=usedforsecurity) else: hashlib.new(digestname, usedforsecurity=usedforsecurity) except ValueError: raise unittest.SkipTest( f"hash digest '{digestname}' is not available." ) return func(*args, **kwargs) return wrapper return decorator ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45042> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com