diff --git a/django/test/html.py b/django/test/html.py index 84f48626932..195c61ede09 100644 --- a/django/test/html.py +++ b/django/test/html.py @@ -94,6 +94,9 @@ class Element(object): if not isinstance(element, six.string_types): if self == element: return 1 + if isinstance(element, RootElement): + if self.children == element.children: + return 1 i = 0 for child in self.children: # child is text content and element is also text content, then diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index 16c48909148..cd9b723a4e2 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -591,6 +591,8 @@ class HTMLEqualTests(SimpleTestCase): self.assertIn(dom1, dom2) dom1 = parse_html('

bar

') self.assertIn(dom1, dom2) + dom1 = parse_html('

foo

bar

') + self.assertIn(dom2, dom1) def test_count(self): # equal html contains each other one time @@ -626,6 +628,11 @@ class HTMLEqualTests(SimpleTestCase): dom2 = parse_html('

foo

bar

') self.assertEqual(dom2.count(dom1), 0) + # html with a root element contains the same html with no root element + dom1 = parse_html('

foo

bar

') + dom2 = parse_html('

foo

bar

') + self.assertEqual(dom2.count(dom1), 1) + def test_parsing_errors(self): with self.assertRaises(AssertionError): self.assertHTMLEqual('

', '')