How to prevent truncating of string in unit test python

To replace [... chars] and [truncated]... with actual characters (no matter how long, and no matter what the type of the compared values are), add this to your *_test.py file:

if 'unittest.util' in __import__('sys').modules:
    # Show full diff in self.assertEqual.
    __import__('sys').modules['unittest.util']._MAX_LENGTH = 999999999

Indeed, as other answers have noted, setting self.maxDiff = None doesn’t help, it doesn’t make the [... chars] disappear. However, this setting helps showing other types of long diffs, so my recommendation is doing both.

Leave a Comment