diff --git a/django/test/testcases.py b/django/test/testcases.py index eed67e9cda..93ad8b9354 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -784,6 +784,13 @@ class SimpleTestCase(unittest.TestCase): else: if not result: standardMsg = '%s != %s' % (safe_repr(xml1, True), safe_repr(xml2, True)) + diff = ('\n' + '\n'.join( + difflib.ndiff( + six.text_type(xml1).splitlines(), + six.text_type(xml2).splitlines(), + ) + )) + standardMsg = self._truncateMessage(standardMsg, diff) self.fail(self._formatMessage(msg, standardMsg)) def assertXMLNotEqual(self, xml1, xml2, msg=None): diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index d61d797173..6869f49666 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -710,6 +710,19 @@ class XMLEqualTests(SimpleTestCase): with self.assertRaises(AssertionError): self.assertXMLEqual(xml1, xml2) + def test_simple_equal_raises_message(self): + xml1 = "" + xml2 = "" + + msg = '''{xml1} != {xml2} +- ++ +? ++++++++++ +'''.format(xml1=repr(xml1), xml2=repr(xml2)) + + with self.assertRaisesMessage(AssertionError, msg): + self.assertXMLEqual(xml1, xml2) + def test_simple_not_equal(self): xml1 = "" xml2 = ""