Skip to content

Handle NFC/NFD strings that normalize to the same string.#10355

Merged
Zac-HD merged 14 commits into
pytest-dev:mainfrom
itxasos23:main
Oct 10, 2022
Merged

Handle NFC/NFD strings that normalize to the same string.#10355
Zac-HD merged 14 commits into
pytest-dev:mainfrom
itxasos23:main

Conversation

@itxasos23
Copy link
Copy Markdown
Contributor

After a failed assertion of two strings, if they normalize to the same text, encode them in utf-8, show a message and compare their bytes representation to make it clear where the strings are different.

Closes #3426

@itxasos23
Copy link
Copy Markdown
Contributor Author

@Zac-HD please advise on how do you feel about this approach.
I tried to compare in utf-8 as that's what makes more sense in the provided example; do you think there's any better way to nudge the user into reviewing the byte-representation of the strings?

Copy link
Copy Markdown
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

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

Off to a great start - don't forget to add yourself to the AUTHORS file!

Comment thread src/_pytest/assertion/util.py Outdated
Comment thread testing/test_assertion.py Outdated
Comment thread pyproject.toml Outdated
Comment thread src/_pytest/config/__init__.py Outdated
Comment thread src/_pytest/_io/saferepr.py Outdated
Comment thread src/_pytest/_io/saferepr.py Outdated
Comment thread src/_pytest/assertion/util.py
Comment thread src/_pytest/config/__init__.py Outdated
Comment thread testing/test_assertion.py Outdated
Copy link
Copy Markdown
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

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

One key comment below, otherwise looks good to me!

Comment thread src/_pytest/_io/saferepr.py Outdated
Copy link
Copy Markdown
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

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

🎉

@Zac-HD Zac-HD merged commit 78c2c48 into pytest-dev:main Oct 10, 2022
imgbot Bot pushed a commit to kkipngenokoech/pytest that referenced this pull request Apr 18, 2026
…#10355)

Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
imgbot Bot pushed a commit to kkipngenokoech/pytest that referenced this pull request Apr 18, 2026
…#10355)

Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error message when comparing same string in NFC and NFD forms is not clear on Python 3

3 participants