Skip to content

Show whitespace escape code in string diffs #10704

Open

Description

@jakkdl

What's the problem this feature will solve?

I just had an assert output the following:

>       assert expected == out
E       AssertionError: assert '/home/h/Git/...ocess, ...)` ' == '/home/h/Git/...cess, ...)`\n'
E         Skipping 160 identical leading characters in diff, use -v to show
E         - ess, ...)`
E         ?           ^
E         + ess, ...)` 
E         ?           ^

very helpfully pointing out that ... my space is not a good space? In fact I had a space instead of a newline, but this message certainly isn't terribly helpful in showing that. Throwing on more -v's also doesn't make a difference. This is particularly egregious if it's at the end of the string, but you get unhelpful messages in other cases as well.

In the "short test summary info" it is actually shown, but only if it's at the end or is a short string - and I personally only noticed that when looking closer at the output while writing this issue.
EDIT: I also now saw that in the first line with the AssertionError it's also shown. So it is only the supposedly helpful extra printout that doesn't have it.

=================================== short test summary info ===================================
FAILED tests/test_flake8_trio.py::test_anyio_from_config - AssertionError: assert '/home/h/Git/...ocess, ...)` ' == '/home/h/Git/...cess, ...)`\n'

Describe the solution you'd like

Print the repr (or \t/\n) in the AssertionError diff printout - at least if that's among the characters that differ.

This only took me a second to figure out personally in this case, and maybe that's the case in the vast majority of the cases it happens such that it's not worth the effort to implement / overly noisy. But I figured it's worth considering - esp as it's inconsistent with the other printouts.

Additional context

$ pytest --version
pytest 7.2.1

No flags, and pretty sure I have no pytest configuration playing into this.

Activity

  1. added
    type: enhancementnew feature or API change, should be merged into features branch
    topic: rewriterelated to the assertion rewrite mechanism
    on Feb 5, 2023
  2. HSamiul commented on Apr 16, 2023

    @HSamiul

    I will try to implement the proposed solution in my own fork and hopefully make a PR for it. Is there any way to officially "claim" this issue?

  3. jakkdl commented on Apr 17, 2023

    @jakkdl
    MemberAuthor

    Awesome, good luck! ⭐

  4. egwetzel commented on May 2, 2023

    @egwetzel

    Would you prefer that this ability to show spaces like \t and \n is activated by calling pytest with a new flag or that it is always implemented when running pytest?

  5. jakkdl commented on May 3, 2023

    @jakkdl
    MemberAuthor

    I think this should be default behaviour

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: rewriterelated to the assertion rewrite mechanismtype: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions