Skip to content

Commit dd7b816

Browse files
bpo-45042: Now test classes decorated with requires_hashdigest are not skipped (GH-28060)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent a1ba359 commit dd7b816

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3773,6 +3773,7 @@ def _attach_existing_shmem_then_write(shmem_name_or_obj, binary_data):
37733773
local_sms.buf[:len(binary_data)] = binary_data
37743774
local_sms.close()
37753775

3776+
@unittest.skipIf(sys.platform == "win32", "test is broken on Windows")
37763777
def test_shared_memory_basics(self):
37773778
sms = shared_memory.SharedMemory('test01_tsmb', create=True, size=512)
37783779
self.addCleanup(sms.unlink)

Lib/test/support/hashlib_helper.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,21 @@ def requires_hashdigest(digestname, openssl=None, usedforsecurity=True):
2121
ValueError: [digital envelope routines: EVP_DigestInit_ex] disabled for FIPS
2222
ValueError: unsupported hash type md4
2323
"""
24-
def decorator(func):
25-
@functools.wraps(func)
24+
def decorator(func_or_class):
25+
if isinstance(func_or_class, type):
26+
setUpClass = func_or_class.__dict__.get('setUpClass')
27+
if setUpClass is None:
28+
def setUpClass(cls):
29+
super(func_or_class, cls).setUpClass()
30+
setUpClass.__qualname__ = func_or_class.__qualname__ + '.setUpClass'
31+
setUpClass.__module__ = func_or_class.__module__
32+
else:
33+
setUpClass = setUpClass.__func__
34+
setUpClass = classmethod(decorator(setUpClass))
35+
func_or_class.setUpClass = setUpClass
36+
return func_or_class
37+
38+
@functools.wraps(func_or_class)
2639
def wrapper(*args, **kwargs):
2740
try:
2841
if openssl and _hashlib is not None:
@@ -33,6 +46,6 @@ def wrapper(*args, **kwargs):
3346
raise unittest.SkipTest(
3447
f"hash digest '{digestname}' is not available."
3548
)
36-
return func(*args, **kwargs)
49+
return func_or_class(*args, **kwargs)
3750
return wrapper
3851
return decorator

Lib/test/test_tools/test_md5sum.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for the md5sum script in the Tools directory."""
22

3+
import sys
34
import os
45
import unittest
56
from test.support import os_helper
@@ -15,16 +16,16 @@ class MD5SumTests(unittest.TestCase):
1516
@classmethod
1617
def setUpClass(cls):
1718
cls.script = os.path.join(scriptsdir, 'md5sum.py')
18-
os.mkdir(os_helper.TESTFN)
19-
cls.fodder = os.path.join(os_helper.TESTFN, 'md5sum.fodder')
19+
os.mkdir(os_helper.TESTFN_ASCII)
20+
cls.fodder = os.path.join(os_helper.TESTFN_ASCII, 'md5sum.fodder')
2021
with open(cls.fodder, 'wb') as f:
2122
f.write(b'md5sum\r\ntest file\r\n')
2223
cls.fodder_md5 = b'd38dae2eb1ab346a292ef6850f9e1a0d'
2324
cls.fodder_textmode_md5 = b'a8b07894e2ca3f2a4c3094065fa6e0a5'
2425

2526
@classmethod
2627
def tearDownClass(cls):
27-
os_helper.rmtree(os_helper.TESTFN)
28+
os_helper.rmtree(os_helper.TESTFN_ASCII)
2829

2930
def test_noargs(self):
3031
rc, out, err = assert_python_ok(self.script)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes that test classes decorated with ``@hashlib_helper.requires_hashdigest`` were skipped all the time.

0 commit comments

Comments
 (0)