Skip to content

Commit 5c09b33

Browse files
committed
Merge pull request #1423 from lukas-bednar/junit_properties
junit: allow multiple properties with same name
2 parents 3445bda + 7e758a9 commit 5c09b33

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Jurko Gospodnetić
5252
Katarzyna Jachim
5353
Kevin Cox
5454
Lee Kamentsky
55+
Lukas Bednar
5556
Maciek Fijalkowski
5657
Maho
5758
Marc Schlaich

CHANGELOG.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,16 @@
9898
(auto/long/short/line/native/no), with `auto` being the default since v2.6.
9999
Thanks `@hackebrot`_ for the PR.
100100

101-
*
101+
* Fix (`#1422`_): junit record_xml_property doesn't allow multiple records
102+
with same name.
102103

103104
*
104105

105106
*
106107

107108
.. _`traceback style docs`: https://pytest.org/latest/usage.html#modifying-python-traceback-printing
108109

110+
.. _#1422: https://github.com/pytest-dev/pytest/issues/1422
109111
.. _#1379: https://github.com/pytest-dev/pytest/issues/1379
110112
.. _#1366: https://github.com/pytest-dev/pytest/issues/1366
111113
.. _#1040: https://github.com/pytest-dev/pytest/pull/1040

_pytest/junitxml.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ def __init__(self, nodeid, xml):
6565
self.xml = xml
6666
self.add_stats = self.xml.add_stats
6767
self.duration = 0
68-
self.properties = {}
69-
self.property_insert_order = []
68+
self.properties = []
7069
self.nodes = []
7170
self.testcase = None
7271
self.attrs = {}
@@ -76,18 +75,15 @@ def append(self, node):
7675
self.nodes.append(node)
7776

7877
def add_property(self, name, value):
79-
name = str(name)
80-
if name not in self.property_insert_order:
81-
self.property_insert_order.append(name)
82-
self.properties[name] = bin_xml_escape(value)
78+
self.properties.append((str(name), bin_xml_escape(value)))
8379

8480
def make_properties_node(self):
8581
"""Return a Junit node containing custom properties, if any.
8682
"""
8783
if self.properties:
8884
return Junit.properties([
89-
Junit.property(name=name, value=self.properties[name])
90-
for name in self.property_insert_order
85+
Junit.property(name=name, value=value)
86+
for name, value in self.properties
9187
])
9288
return ''
9389

testing/test_junitxml.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,21 @@ def test_record(record_xml_property, other):
669669
result.stdout.fnmatch_lines('*C3*test_record_property.py*experimental*')
670670

671671

672+
def test_record_property_same_name(testdir):
673+
testdir.makepyfile("""
674+
def test_record_with_same_name(record_xml_property):
675+
record_xml_property("foo", "bar")
676+
record_xml_property("foo", "baz")
677+
""")
678+
result, dom = runandparse(testdir, '-rw')
679+
node = dom.find_first_by_tag("testsuite")
680+
tnode = node.find_first_by_tag("testcase")
681+
psnode = tnode.find_first_by_tag('properties')
682+
pnodes = psnode.find_by_tag('property')
683+
pnodes[0].assert_attr(name="foo", value="bar")
684+
pnodes[1].assert_attr(name="foo", value="baz")
685+
686+
672687
def test_random_report_log_xdist(testdir):
673688
"""xdist calls pytest_runtest_logreport as they are executed by the slaves,
674689
with nodes from several nodes overlapping, so junitxml must cope with that

0 commit comments

Comments
 (0)