Source code for cfme.markers.polarion

# -*- coding: utf-8 -*-
"""polarion(\*tcid): Marker for marking tests as automation for polarion test cases."""
import pytest
import attr
from fixtures.pytest_store import store


[docs]def pytest_configure(config): config.addinivalue_line("markers", __doc__.splitlines()[0])
[docs]def extract_polarion_ids(item): """Extracts Polarion TC IDs from the test item. Returns None if no marker present.""" polarion = item.get_marker('polarion') return map(str, getattr(polarion, 'args', []))
[docs]@pytest.mark.tryfirst 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}, ))
[docs]@attr.s(hash=False) class ReportPolarionToJunitPlugin(object): xml = attr.ib() node_map = attr.ib()
[docs] @pytest.mark.tryfirst 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)