Skip to content

Conversation

cmnemoi
Copy link

@cmnemoi cmnemoi commented Oct 15, 2025

Hello,

This PR fixes an issue with pytest.approx where the error message was not clear when comparing mappings with different keys. Previously, the comparison would proceed and report -inf mismatches on values or a KeyError, leading to confusing error messages.

The fix adds an early check in ApproxMapping to compare the sets of keys between the expected and actual mappings. If they differ, it returns a clear error message indicating the different keys.

This closes #13816.

Checklist

  • I have included new tests or updated existing ones where applicable.
  • I have created a new changelog file in the changelog folder, named <ISSUE NUMBER>.<TYPE>.rst.
  • I have added myself to AUTHORS in alphabetical order.
  • I have added text like "closes #XYZW" to the PR description.
  • I have allowed maintainers to push and squash when merging my commits.
  • I have included documentation when adding new features. (Not applicable here – this is a bug fix.)

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Oct 15, 2025
@cmnemoi cmnemoi changed the title fix(testing): pytest.approx returns a clearer error mesage when comparing mappings with different keys fix(testing): pytest.approx returns a clearer error mesage when comparing mappings with different keys Oct 15, 2025
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.approx gives confusing error when dictionaries have different keys

1 participant