import difflib
expected = expected.splitlines(1)
actual = actual.splitlines(1)
diff = difflib.unified_diff(expected, actual)
return ''.join(diff)
Как напечатать сравнение двух многострочных строк в едином формате diff?