FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(testing): `pytest.approx` returns a clearer error mesage when comparing mappings with different keys by cmnemoi · Pull Request #13818 · pytest-dev/pytest · GitHub

fix(testing): pytest.approx returns a clearer error mesage when comparing mappings with different keys - #13818

Merged
nicoddemus merged 4 commits into
pytest-dev:mainfrom
cmnemoi-oss:fix/13816
Nov 1, 2025
Merged

fix(testing): pytest.approx returns a clearer error mesage when comparing mappings with different keys#13818
nicoddemus merged 4 commits into
pytest-dev:mainfrom
cmnemoi-oss:fix/13816

Conversation

cmnemoi commented Oct 15, 2025
edited
Loading

Copy link
Copy Markdown
Contributor

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 Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Oct 15, 2025
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

cmnemoi commented Oct 20, 2025

Copy link
Copy Markdown
Contributor Author

Hello @bluetech, can I have a review here ? It should be fast.

nicoddemus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looks good, thanks! Sorry for the delay in reviewing this.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

2 participants


Back | FazBrowse Home | New Git URL