diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index d7aeec96d..3e0ca147a 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -64,10 +64,14 @@ class _NodeReporter(object): self.id = nodeid self.duration = 0 self.properties = {} + self.property_insert_order = [] self.testcase = None def add_property(self, name, value): - self.properties[str(name)] = bin_xml_escape(value) + name = str(name) + if name not in self.property_insert_order: + self.property_insert_order.append(name) + self.properties[name] = bin_xml_escape(value) def make_properties_node(self): @@ -76,8 +80,8 @@ class _NodeReporter(object): """ if self.properties: return Junit.properties([ - Junit.property(name=name, value=value) - for name, value in self.properties.items() + Junit.property(name=name, value=self.properties[name]) + for name in self.property_insert_order ]) diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index e6df2150c..75819694f 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -32,6 +32,9 @@ class DomNode(object): def __init__(self, dom): self.__node = dom + def __repr__(self): + return self.__node.toxml() + def find_first_by_tag(self, tag): return self.find_nth_by_tag(tag, 0) @@ -629,8 +632,9 @@ def test_record_property(testdir): node = dom.find_first_by_tag("testsuite") tnode = node.find_first_by_tag("testcase") psnode = tnode.find_first_by_tag('properties') - pnode = psnode.find_first_by_tag('property') - pnode.assert_attr(name="foo", value="<1") + pnodes = psnode.find_by_tag('property') + pnodes[0].assert_attr(name="bar", value="1") + pnodes[1].assert_attr(name="foo", value="<1") result.stdout.fnmatch_lines('*C3*test_record_property.py*experimental*')