Skip to content

fix: catch KeyError when accessing __name__ in _idval_from_value (#14560)#14561

Open
NIK-TIGER-BILL wants to merge 2 commits into
pytest-dev:mainfrom
NIK-TIGER-BILL:fix-idval-from-value-keyerror
Open

fix: catch KeyError when accessing __name__ in _idval_from_value (#14560)#14561
NIK-TIGER-BILL wants to merge 2 commits into
pytest-dev:mainfrom
NIK-TIGER-BILL:fix-idval-from-value-keyerror

Conversation

@NIK-TIGER-BILL
Copy link
Copy Markdown

Description

Fixes #14560.

Custom classes with a __getattr__ that raises KeyError (instead of AttributeError) would crash pytest during parameterized test id generation. This PR catches both AttributeError and KeyError when trying to access __name__.

Checklist

  • Include new tests or update existing tests when applicable.
  • Allow maintainers to push and squash when merging my commits.
  • Add text like closes #14560 to the PR description and/or commits.
  • Create a new changelog file in the changelog directory.
  • Add yourself to AUTHORS in alphabetical order.

…est-dev#14560)

Custom classes with a __getattr__ that raises KeyError instead of
AttributeError would crash pytest during parameterized test id
generation. We now catch both AttributeError and KeyError.

Fixes pytest-dev#14560

Signed-off-by: NIK-TIGER-BILL <nik.tiger.bill@github.com>
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pytest can't handle custom classes in parameterized tests (major bug).

1 participant