Demonstrating how bad the wrapped message is, they should be the same by txomon · Pull Request #57 · pytest-dev/pytest-mock (original) (raw)

This test demonstrates how bad those assert wraps in the library can be.

Is totally misleading and displays incomplete information.

The output of the test so that you understand the big difference:

E       assert 'Expected cal...ock(a=1, b=2)' == 'assert () == ...()\n  + (1, 2)'
E         - Expected call: mock(1, 2)
E         - Actual call: mock(a=1, b=2)
E         + assert () == (1, 2)
E         +   Right contains more items, first extra item: 1
E         +   Full diff:
E         +   - ()
E         +   + (1, 2)

As you can see, the actual message (marked with + in the diff) doesn't speak at all about the keyword arguments, and although the diff may be more verbose all the content there is terrible.

This needs to improve by either making:

  1. Both messages the same
  2. Improve it until all the data appears in the assert message

IMO the assert wrapper function should just disappear, but up to you.

EDIT: Instead of creating the exception again, I would really raise the existing one within the assert wrapper

EDIT2: I think it would also be nice to know why the assert wrapper is necessary at all...

EDIT3: Just in case, tests fail on purpose.