﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30497	assertXMLEqual chokes on document type declaration	Yuri Kanivetsky	nobody	"Prepare Django project:

{{{
$ python -m venv env
$ . ./env/bin/activate
$ pip install django
$ django-admin startproject p1
$ cd p1
}}}

Create `p1/tests.py`:

{{{
#!python
from django.test import TestCase

class MyTestCase(TestCase):
    def test_assert_xml_equal(self):
        xml1 = '''
            <?xml version=""1.0"" encoding=""UTF-8""?>
            <!DOCTYPE root SYSTEM ""example.dtd"">
            <root />
        '''
        xml2 = '''
            <?xml version=""1.0"" encoding=""UTF-8""?>
            <!DOCTYPE root SYSTEM ""example.dtd"">
            <root />
        '''
        self.assertXMLEqual(xml1, xml2)
}}}

Run the tests:

{{{
$ ./manage.py test
Creating test database for alias 'default'...
F
======================================================================
FAIL: test_assert_xml_equal (p1.tests.MyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""/home/yuri/_/1/env/lib/python3.7/site-packages/django/test/testcases.py"", line 843, in assertXMLEqual
    result = compare_xml(xml1, xml2)
  File ""/home/yuri/_/1/env/lib/python3.7/site-packages/django/test/utils.py"", line 598, in compare_xml
    return check_element(want_root, got_root)
AttributeError: 'DocumentType' object has no attribute 'tagName'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ""/home/yuri/_/1/p1/p1/tests.py"", line 15, in test_assert_xml_equal
    self.assertXMLEqual(xml1, xml2)
  File ""/home/yuri/_/1/env/lib/python3.7/site-packages/django/test/testcases.py"", line 846, in assertXMLEqual
    self.fail(self._formatMessage(msg, standardMsg))
AssertionError: First or second argument is not valid XML
'DocumentType' object has no attribute 'tagName'

----------------------------------------------------------------------
Ran 1 test in 0.002s

FAILED (failures=1)
Destroying test database for alias 'default'...
System check identified no issues (0 silenced).
}}}

That happens because `django.utils` expects first [https://github.com/django/django/blob/2.2.1/django/test/utils.py#L595-L596 non-comment] element to be the [https://github.com/django/django/blob/2.2.1/django/test/utils.py#L579-L582 root] element. Which is generally not the case."	Bug	new	Testing framework	2.2	Normal				Unreviewed	0	0	0	0	0	0
