gh-145028: Fix blake2 tests in test_hashlib when it is missing due to configure --without-builtin-hashlib-hashes#145029
gh-145028: Fix blake2 tests in test_hashlib when it is missing due to configure --without-builtin-hashlib-hashes#145029tucif wants to merge 3 commits intopython:mainfrom
Conversation
…_algorithms_available if implementation is not provided
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Lib/test/test_hashlib.py
Outdated
| try: | ||
| digest = hashlib.new(name, usedforsecurity=False) | ||
| assert digest is not None | ||
| except ValueError as verr: | ||
| # builtins may be absent if python built with | ||
| # a subset of --with-builtin-hashlib-hashes or none. | ||
| self.skipTest(verr) |
There was a problem hiding this comment.
This basically skips the point of the test which is to ensure that everything is available as written. modify the skipping to only skip on blake2 if it was not configured to be available perhaps:
if ("blake2" in name and
"blake2" not in sysconfig.get_config_var("PY_BUILTIN_HASHLIB_HASHES").split(",")):
self.skipTest(verr)
else:
raise
Given that blake2 is never going to be provided by a non-builtin.
There was a problem hiding this comment.
Thanks for reviewing! Applied the suggestion.
…st_algorithms_available
Lib/test/test_hashlib.py
Outdated
| if _blake2: | ||
| mods.append('_blake2') |
There was a problem hiding this comment.
IIRC, you don't need to have the check here. find_gil_minsize() should skip the module if it can't be found (IIRC)
There was a problem hiding this comment.
oh right, nice helper! removed this.
Lib/test/test_hashlib.py
Outdated
| if ("blake2" in name and | ||
| "blake2" not in sysconfig.get_config_var("PY_BUILTIN_HASHLIB_HASHES").split(",")): |
There was a problem hiding this comment.
Move the sysconfig stuff outside the loop please.
| if _blake2: | ||
| algos.append('blake2s') |
There was a problem hiding this comment.
Not sure that we need this guard here. Or do we?
There was a problem hiding this comment.
Yeah seems like we do, if i remove it:
ERROR: test_threaded_hashing_fast (Lib.test.test_hashlib.HashLibTestCase.test_threaded_hashing_fast) [blake2s]
----------------------------------------------------------------------
Traceback (most recent call last):
File "/.../cpython/Lib/test/test_hashlib.py", line 1104, in test_threaded_hashing_fast
self.do_test_threaded_hashing(constructor, is_shake=False)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.../cpython/Lib/test/test_hashlib.py", line 1134, in do_test_threaded_hashing
h1 = constructor(usedforsecurity=False)
File "<string>", line 14, in blake2s
ValueError: unsupported hash algorithm blake2s
There was a problem hiding this comment.
An alternative is to simply catch the valueerror and skip the test otherwise. I don't think we're very consistent here.
- Moved retrieval of PY_BUILTIN_HASHLIB_HASHES out of the loop - Removed guard from test_gil
This PR addresses Issue #145028 tracking test_hashlib failure on cpython configured
--without-builtin-hashlib-hashesChanges in test_hashlib.py
@require_blake2)algorithmsin constructor when _blake2 is None, as they may already be in that list through its initialization fromself.supported_hashnames.Testing with fix on python without builtin blake2
Sample skips on test_algorithms_available