# -*- coding: utf-8 -*-
"""polarion(\*tcid): Marker for marking tests as automation for polarion test cases."""
import pytest
import attr
from cfme.fixtures.pytest_store import store
@pytest.mark.tryfirst
[docs]def pytest_collection_modifyitems(config, items):
xml = getattr(config, '_xml', None)
if xml is None:
return
if store.parallelizer_role != 'master':
return
config.pluginmanager.register(ReportPolarionToJunitPlugin(
xml=xml,
node_map={item.nodeid: extract_polarion_ids(item) for item in items},
))
@attr.s(hash=False)
[docs]class ReportPolarionToJunitPlugin(object):
xml = attr.ib()
node_map = attr.ib()
@pytest.mark.tryfirst
[docs] def pytest_runtest_logreport(self, report):
"""Adds the supplied test case id to the xunit file as a property"""
if report.when != 'setup':
return
reporter = self.xml.node_reporter(report)
polarion_ids = self.node_map.get(report.nodeid, [])
for polarion_id in polarion_ids:
reporter.add_property('test_id', polarion_id)