Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 14 commits into from Oct 10, 2022

Conversation

itxasos23
Copy link
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
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
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!

src/_pytest/assertion/util.py Outdated Show resolved Hide resolved
testing/test_assertion.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
src/_pytest/_io/saferepr.py Outdated Show resolved Hide resolved
src/_pytest/_io/saferepr.py Outdated Show resolved Hide resolved
src/_pytest/assertion/util.py Show resolved Hide resolved
src/_pytest/config/__init__.py Outdated Show resolved Hide resolved
testing/test_assertion.py Outdated Show resolved Hide resolved
Copy link
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!

src/_pytest/_io/saferepr.py Outdated Show resolved Hide resolved
Copy link
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
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