Skip to content

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

@pekkaklarck

Description

@pekkaklarck

If I compare same string in different Unicode normal forms the error message doesn't show any differences between them when using Python 3. For example, if I have a test like

def test_nfc_nfd():
    nfc = 'hyv\xe4'
    nfd = 'hyva\u0308'
    assert nfc == nfd

the result I got is

>       assert nfc == nfd
E       AssertionError: assert 'hyvä' == 'hyvä'
E         - hyvä
E         + hyvä

which isn't very informative.

The problem is caused by repr('hyva\u0308') being 'hyva\u0308' which is rendered as 'hyvä'. I submitted an issue about repr() escaping combining characters (i.e. turning the result to 'hyva\\u0308') but it was closed as invalid.

In PyTest it would be possible to use ascii() instead of repr(), but that would make all non-ASCII strings unreadable and that would be worse. I guess the best solution would be using ascii() if strings look the same, but I have no idea how to detect that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueeasy issue that is friendly to new contributortopic: reportingrelated to terminal output and user-facing messages and errorstopic: rewriterelated to the assertion rewrite mechanism

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions