def isEqualElement(a, b):
    if a.tagName != b.tagName:
        return False
if sorted(a.attributes.items()) != sorted(b.attributes.items()):
    return False
if len(a.childNodes) != len(b.childNodes):
    return False
for ac, bc in zip(a.childNodes, b.childNodes):
    if ac.nodeType != bc.nodeType:
        return False
if ac.nodeType == ac.TEXT_NODE and ac.data != bc.data:
    return False
if ac.nodeType == ac.ELEMENT_NODE and not isEqualElement(ac, bc):
    return False
return True
Сравнение XML в модульном тесте в Python