guettli guettli - 2 years ago 98
Python Question

Python: self.assertEqual(a, b, msg) --> I want diff AND msg

If I call it like this, I see a nice diff:

self.assertEqual(a, b)

If I call it like this, I see the msg only:

self.assertEqual(a, b, msg)

Is there an easy way to show the diff AND the msg?

myself would work, but I ask myself if this is really the best way.

Plattform: Python2.7 and pytest 2.6.2.

Answer Source

If you set longMessage attribute True, you will see both message.


class TestFoo(unittest.TestCase):

    longMessage = True  # <--

    def test_foo(self):
        self.assertEqual(1+2, 2, 'custom message')


FAIL: test_foo (__main__.TestFoo)
Traceback (most recent call last):
  File "", line 6, in test_foo
    self.assertEqual(1+2, 2, 'custom message')
AssertionError: 3 != 2 : custom message

Ran 1 test in 0.000s
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download