Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.10] bpo-45042: Now test classes decorated with requires_hashdigest are not skipped (GH-28060) #28168

Merged
merged 1 commit into from Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/test/_test_multiprocessing.py
Expand Up @@ -3771,6 +3771,7 @@ def _attach_existing_shmem_then_write(shmem_name_or_obj, binary_data):
local_sms.buf[:len(binary_data)] = binary_data
local_sms.close()

@unittest.skipIf(sys.platform == "win32", "test is broken on Windows")
def test_shared_memory_basics(self):
sms = shared_memory.SharedMemory('test01_tsmb', create=True, size=512)
self.addCleanup(sms.unlink)
Expand Down
19 changes: 16 additions & 3 deletions Lib/test/support/hashlib_helper.py
Expand Up @@ -21,8 +21,21 @@ def requires_hashdigest(digestname, openssl=None, usedforsecurity=True):
ValueError: [digital envelope routines: EVP_DigestInit_ex] disabled for FIPS
ValueError: unsupported hash type md4
"""
def decorator(func):
@functools.wraps(func)
def decorator(func_or_class):
if isinstance(func_or_class, type):
setUpClass = func_or_class.__dict__.get('setUpClass')
if setUpClass is None:
def setUpClass(cls):
super(func_or_class, cls).setUpClass()
setUpClass.__qualname__ = func_or_class.__qualname__ + '.setUpClass'
setUpClass.__module__ = func_or_class.__module__
else:
setUpClass = setUpClass.__func__
setUpClass = classmethod(decorator(setUpClass))
func_or_class.setUpClass = setUpClass
return func_or_class

@functools.wraps(func_or_class)
def wrapper(*args, **kwargs):
try:
if openssl and _hashlib is not None:
Expand All @@ -33,6 +46,6 @@ def wrapper(*args, **kwargs):
raise unittest.SkipTest(
f"hash digest '{digestname}' is not available."
)
return func(*args, **kwargs)
return func_or_class(*args, **kwargs)
return wrapper
return decorator
7 changes: 4 additions & 3 deletions Lib/test/test_tools/test_md5sum.py
@@ -1,5 +1,6 @@
"""Tests for the md5sum script in the Tools directory."""

import sys
import os
import unittest
from test.support import os_helper
Expand All @@ -15,16 +16,16 @@ class MD5SumTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.script = os.path.join(scriptsdir, 'md5sum.py')
os.mkdir(os_helper.TESTFN)
cls.fodder = os.path.join(os_helper.TESTFN, 'md5sum.fodder')
os.mkdir(os_helper.TESTFN_ASCII)
cls.fodder = os.path.join(os_helper.TESTFN_ASCII, 'md5sum.fodder')
with open(cls.fodder, 'wb') as f:
f.write(b'md5sum\r\ntest file\r\n')
cls.fodder_md5 = b'd38dae2eb1ab346a292ef6850f9e1a0d'
cls.fodder_textmode_md5 = b'a8b07894e2ca3f2a4c3094065fa6e0a5'

@classmethod
def tearDownClass(cls):
os_helper.rmtree(os_helper.TESTFN)
os_helper.rmtree(os_helper.TESTFN_ASCII)

def test_noargs(self):
rc, out, err = assert_python_ok(self.script)
Expand Down
@@ -0,0 +1 @@
Fixes that test classes decorated with ``@hashlib_helper.requires_hashdigest`` were skipped all the time.