Skip to content

Conversation

@anuranjansb
Copy link

Summary

Pytest’s assertion summary output currently reorders dictionary keys alphabetically, losing insertion order guaranteed by Python dictionaries.

This PR preserves insertion order in assertion output while keeping existing formatting behavior unchanged.

Problem

Assertion failures involving dictionaries use reprlib.Repr, which sorts dictionary keys internally, leading to confusing output.

Solution

Override dictionary representation in SafeRepr to use dict.__repr__, preserving insertion order.

Tests

Added a regression test to ensure dictionary insertion order is preserved in assertion failure output.

Fixes #13503

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Dec 20, 2025
anuranjansb and others added 20 commits December 21, 2025 01:27
Refactor assertions for getmodpath method to improve clarity.
@anuranjansb
Copy link
Author

After investigating further, this change impacts several existing assertion-diff contracts. I’m closing this PR and will look for a more suitable issue. Thanks for the review tools!

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.

Failure output order of dictionary keys is alphabetical instead of insertion order

1 participant