]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-135571: Guard `_hashlib` usage in `test_hashlib.py` (GH-135572) (#136042)
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Sat, 28 Jun 2025 08:15:39 +0000 (10:15 +0200)
committerGitHub <noreply@github.com>
Sat, 28 Jun 2025 08:15:39 +0000 (10:15 +0200)
(cherry picked from commit 065194c1a971b59547f1bb2cc64760c4bf0ee674)

Co-authored-by: Will Childs-Klein <willck93@gmail.com>
Lib/test/test_hashlib.py

index e25a938562a938422fa94fd745670c9481e1652d..959fe90ff01d478109876047ac42acd2d64d3552 100644 (file)
@@ -263,7 +263,10 @@ class HashLibTestCase(unittest.TestCase):
                 hashlib.new(digest_name, b'')
                 hashlib.new(digest_name, data=b'')
                 hashlib.new(digest_name, string=b'')
-                if self._hashlib:
+                # Make sure that _hashlib contains the constructor
+                # to test when using a combination of libcrypto and
+                # interned hash implementations.
+                if self._hashlib and digest_name in self._hashlib._constructors:
                     self._hashlib.new(digest_name, b'')
                     self._hashlib.new(digest_name, data=b'')
                     self._hashlib.new(digest_name, string=b'')
@@ -315,7 +318,8 @@ class HashLibTestCase(unittest.TestCase):
                 with self.subTest(digest_name, args=args, kwds=kwds):
                     with self.assertRaisesRegex(TypeError, errmsg):
                         hashlib.new(digest_name, *args, **kwds)
-                    if self._hashlib:
+                    if (self._hashlib and
+                            digest_name in self._hashlib._constructors):
                         with self.assertRaisesRegex(TypeError, errmsg):
                             self._hashlib.new(digest_name, *args, **kwds)