Skip to content

py.test should escape \r in error messages #3443

@mgedmin

Description

@mgedmin

py.test doesn't escape \r in assertion messages, which makes the assertion failures very hard to understand. This is best demonstrated with an example:

# test.py
def test_stuff():
    a = u'\r\n'
    assert a == u'\n'
$ py.test test.py
============================= test session starts ==============================
platform linux2 -- Python 2.7.14, pytest-3.5.0, py-1.5.3, pluggy-0.6.0
rootdir: /tmp, inifile:
plugins: xdist-1.22.2, forked-0.2, catchlog-1.2.2
collected 1 item                                                               

test.py F                                                                [100%]

=================================== FAILURES ===================================
__________________________________ test_stuff __________________________________

    def test_stuff():
        a = u'\r\n'
>       assert a == u'\n'
\n' == '\n'ertionError: assert '
E         - 
E         +

test.py:3: AssertionError
=============================== warnings summary ===============================
None
  pytest-catchlog plugin has been merged into the core, please remove it from your requirements.

-- Docs: http://doc.pytest.org/en/latest/warnings.html
===================== 1 failed, 1 warnings in 0.02 seconds =====================

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: reportingrelated to terminal output and user-facing messages and errorstype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions