When I use assertEqual()
with two dictionaries in REPL, it shows me a diff, e.g.:
>>> import unittest
>>> class A(unittest.TestCase):
... pass
...
>>> a = A()
>>> d1 = dict(zip(range(10), range(1000000, 1000010)))
>>> d2 = dict(zip(range(3, 13), range(1000003, 1000013)))
>>> a.assertEqual(d1, d2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.5/unittest/case.py", line 820, in assertEqual
assertion_func(first, second, msg=msg)
File "/usr/lib/python3.5/unittest/case.py", line 1111, in assertDictEqual
self.fail(self._formatMessage(msg, standardMsg))
File "/usr/lib/python3.5/unittest/case.py", line 665, in fail
raise self.failureException(msg)
AssertionError: {0: 1000000, 1: 1000001, 2: 1000002, 3: 10[73 chars]0009} != {3: 1000003, 4: 1000004, 5: 1000005, 6: 10[76 chars]0012}
- {0: 1000000,
- 1: 1000001,
- 2: 1000002,
- 3: 1000003,
? ^
+ {3: 1000003,
? ^
4: 1000004,
5: 1000005,
6: 1000006,
7: 1000007,
8: 1000008,
- 9: 1000009}
? ^
+ 9: 1000009,
? ^
+ 10: 1000010,
+ 11: 1000011,
+ 12: 1000012}
When I do the same in a Django unit test, sometimes it prints a diff and sometimes only the first shortened line. I wonder, how can I make it always print the diff.
I run Django tests with ./manage.py test -v 3
.