Skip to content

Comments

gh-145028: Fix blake2 tests in test_hashlib when it is missing due to configure --without-builtin-hashlib-hashes#145029

Open
tucif wants to merge 3 commits intopython:mainfrom
tucif:tucif/without_blake2
Open

gh-145028: Fix blake2 tests in test_hashlib when it is missing due to configure --without-builtin-hashlib-hashes#145029
tucif wants to merge 3 commits intopython:mainfrom
tucif:tucif/without_blake2

Conversation

@tucif
Copy link

@tucif tucif commented Feb 20, 2026

This PR addresses Issue #145028 tracking test_hashlib failure on cpython configured --without-builtin-hashlib-hashes

Changes in test_hashlib.py

  • Guard testing of blake2 with existing utils to verify its existence (@require_blake2)
  • Remove blake2 variations from algorithms in constructor when _blake2 is None, as they may already be in that list through its initialization from self.supported_hashnames.
  • Add subtests in test_algorithms_available and skip if ValueError is raised, so it's easy to tell what exactly was skipped and why.
  • Conditionally add blake2 on test*gil that had previously hardcoded it to their check lists.

Testing with fix on python without builtin blake2

python -m unittest Lib.test.test_hashlib.HashLibTestCase
...
----------------------------------------------------------------------
Ran 82 tests in 7.005s

OK (skipped=29)

Sample skips on test_algorithms_available

  test_algorithms_available (Lib.test.test_hashlib.HashLibTestCase.test_algorithms_available) [blake2b] ... skipped 'unsupported hash algorithm blake2b'
  test_algorithms_available (Lib.test.test_hashlib.HashLibTestCase.test_algorithms_available) [blake2s] ... skipped 'unsupported hash algorithm blake2s'

…_algorithms_available if implementation is not provided
@python-cla-bot
Copy link

python-cla-bot bot commented Feb 20, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Feb 20, 2026

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 skip news label instead.

Comment on lines 239 to 245
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing! Applied the suggestion.

Comment on lines 1071 to 1072
if _blake2:
mods.append('_blake2')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, you don't need to have the check here. find_gil_minsize() should skip the module if it can't be found (IIRC)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right, nice helper! removed this.

Comment on lines 245 to 246
if ("blake2" in name and
"blake2" not in sysconfig.get_config_var("PY_BUILTIN_HASHLIB_HASHES").split(",")):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the sysconfig stuff outside the loop please.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, done.

Comment on lines +1101 to +1102
if _blake2:
algos.append('blake2s')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that we need this guard here. Or do we?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants