Python 3.8 now preserves XML attribute insertion order, rather than sorting them, when writing XML into a file. This change broke the test suite. Example:
FAIL: test_odt_basic (test_writers.test_odt.DocutilsOdtTestCase)
...
AssertionError: content.xml not equal: expected len: 1961 actual len: 1961
Change introduced in Python 3.8 by:
* https://github.com/python/cpython/commit/5598cc90c745dab827e55fadded42dbe85e31d33
* https://bugs.python.org/issue34160
The issue has been detected on Fedora Rawhide while testing Python 3.8: https://bugzilla.redhat.com/show_bug.cgi?id=1687377
might be due to some changes in sorting of keys/fields
The Python ElementTree documentation now suggests this recipe to sort XML attributes:
def reorder_attributes(root):
for el in root.iter():
attrib = el.attrib
if len(attrib) > 1:
# adjust attribute order, e.g. by sorting
attribs = sorted(attrib.items())
attrib.clear()
attrib.update(attribs)
This function can be used in any Python versions.
https://docs.python.org/dev/library/xml.etree.elementtree.html
many thanks