Skip to content

fix(testing): pytest.approx correctly take account Mapping keys order to compare them#13815

Merged
nicoddemus merged 10 commits into
pytest-dev:mainfrom
cmnemoi-oss:fix/12444
Jan 25, 2026
Merged

fix(testing): pytest.approx correctly take account Mapping keys order to compare them#13815
nicoddemus merged 10 commits into
pytest-dev:mainfrom
cmnemoi-oss:fix/12444

Conversation

@cmnemoi

@cmnemoi cmnemoi commented Oct 15, 2025

Copy link
Copy Markdown
Contributor

Hello,

This PR fixes an issue with pytest.approx where the error message incorrectly reported all elements as mismatched when comparing mappings with different key orders, even when only some values differed.

The original code paired values by position rather than by key. This caused incorrect mismatch reporting when dictionary keys were in different orders.

This closes #12444.

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 commented Oct 20, 2025

Copy link
Copy Markdown
Contributor Author

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

@cmnemoi
cmnemoi force-pushed the fix/12444 branch 2 times, most recently from ad30e6c to 99d108b Compare December 2, 2025 14:37
@cmnemoi

cmnemoi commented Dec 2, 2025

Copy link
Copy Markdown
Contributor Author

Hello @nicoddemus, thanks for your review for #13818

Here is a similar contribution to take a look to when you have the time

Comment thread src/_pytest/python_api.py Outdated
Comment thread testing/python/approx.py Outdated
Comment thread testing/python/approx.py

@nicoddemus 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.

Thanks!

@nicoddemus
nicoddemus enabled auto-merge (squash) January 25, 2026 12:48
@nicoddemus
nicoddemus merged commit e95a843 into pytest-dev:main Jan 25, 2026
33 checks passed
@patchback

patchback Bot commented Jan 25, 2026

Copy link
Copy Markdown

Backport to 9.0.x: 💚 backport PR created

✅ Backport PR branch: patchback/backports/9.0.x/e95a843a5dbf8af618d0714705bbf97dfdb04044/pr-13815

Backported as #14142

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback Bot pushed a commit that referenced this pull request Jan 25, 2026
…pare them (#13815)

This fixes an issue with `pytest.approx` where the error message incorrectly reported all elements as mismatched when comparing mappings with different key orders, even when only some values differed.

The original code paired values by position rather than by key. This caused incorrect mismatch reporting when dictionary keys were in different orders.

Fixes #12444

(cherry picked from commit e95a843)
nicoddemus pushed a commit that referenced this pull request Jan 25, 2026
…pare them (#13815) (#14142)

This fixes an issue with `pytest.approx` where the error message incorrectly reported all elements as mismatched when comparing mappings with different key orders, even when only some values differed.

The original code paired values by position rather than by key. This caused incorrect mismatch reporting when dictionary keys were in different orders.

Fixes #12444

(cherry picked from commit e95a843)

Co-authored-by: Charles-Meldhine Madi Mnemoi <63333367+cmnemoi@users.noreply.github.com>
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 wrong formatting return - printing all values as wrong.

2 participants