Merge pull request #1423 from lukas-bednar/junit_properties

junit: allow multiple properties with same name
This commit is contained in:
Bruno Oliveira 2016-02-29 15:35:03 -03:00
commit 5c09b33150
4 changed files with 23 additions and 9 deletions

View File

@ -52,6 +52,7 @@ Jurko Gospodnetić
Katarzyna Jachim Katarzyna Jachim
Kevin Cox Kevin Cox
Lee Kamentsky Lee Kamentsky
Lukas Bednar
Maciek Fijalkowski Maciek Fijalkowski
Maho Maho
Marc Schlaich Marc Schlaich

View File

@ -98,7 +98,8 @@
(auto/long/short/line/native/no), with `auto` being the default since v2.6. (auto/long/short/line/native/no), with `auto` being the default since v2.6.
Thanks `@hackebrot`_ for the PR. Thanks `@hackebrot`_ for the PR.
* * Fix (`#1422`_): junit record_xml_property doesn't allow multiple records
with same name.
* *
@ -106,6 +107,7 @@
.. _`traceback style docs`: https://pytest.org/latest/usage.html#modifying-python-traceback-printing .. _`traceback style docs`: https://pytest.org/latest/usage.html#modifying-python-traceback-printing
.. _#1422: https://github.com/pytest-dev/pytest/issues/1422
.. _#1379: https://github.com/pytest-dev/pytest/issues/1379 .. _#1379: https://github.com/pytest-dev/pytest/issues/1379
.. _#1366: https://github.com/pytest-dev/pytest/issues/1366 .. _#1366: https://github.com/pytest-dev/pytest/issues/1366
.. _#1040: https://github.com/pytest-dev/pytest/pull/1040 .. _#1040: https://github.com/pytest-dev/pytest/pull/1040

View File

@ -65,8 +65,7 @@ class _NodeReporter(object):
self.xml = xml self.xml = xml
self.add_stats = self.xml.add_stats self.add_stats = self.xml.add_stats
self.duration = 0 self.duration = 0
self.properties = {} self.properties = []
self.property_insert_order = []
self.nodes = [] self.nodes = []
self.testcase = None self.testcase = None
self.attrs = {} self.attrs = {}
@ -76,18 +75,15 @@ class _NodeReporter(object):
self.nodes.append(node) self.nodes.append(node)
def add_property(self, name, value): def add_property(self, name, value):
name = str(name) self.properties.append((str(name), bin_xml_escape(value)))
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): def make_properties_node(self):
"""Return a Junit node containing custom properties, if any. """Return a Junit node containing custom properties, if any.
""" """
if self.properties: if self.properties:
return Junit.properties([ return Junit.properties([
Junit.property(name=name, value=self.properties[name]) Junit.property(name=name, value=value)
for name in self.property_insert_order for name, value in self.properties
]) ])
return '' return ''

View File

@ -669,6 +669,21 @@ def test_record_property(testdir):
result.stdout.fnmatch_lines('*C3*test_record_property.py*experimental*') result.stdout.fnmatch_lines('*C3*test_record_property.py*experimental*')
def test_record_property_same_name(testdir):
testdir.makepyfile("""
def test_record_with_same_name(record_xml_property):
record_xml_property("foo", "bar")
record_xml_property("foo", "baz")
""")
result, dom = runandparse(testdir, '-rw')
node = dom.find_first_by_tag("testsuite")
tnode = node.find_first_by_tag("testcase")
psnode = tnode.find_first_by_tag('properties')
pnodes = psnode.find_by_tag('property')
pnodes[0].assert_attr(name="foo", value="bar")
pnodes[1].assert_attr(name="foo", value="baz")
def test_random_report_log_xdist(testdir): def test_random_report_log_xdist(testdir):
"""xdist calls pytest_runtest_logreport as they are executed by the slaves, """xdist calls pytest_runtest_logreport as they are executed by the slaves,
with nodes from several nodes overlapping, so junitxml must cope with that with nodes from several nodes overlapping, so junitxml must cope with that