diff --git a/dump2polarion/exporters/testcases_exporter.py b/dump2polarion/exporters/testcases_exporter.py index 817f4d2..038c10e 100644 --- a/dump2polarion/exporters/testcases_exporter.py +++ b/dump2polarion/exporters/testcases_exporter.py @@ -39,7 +39,7 @@ import datetime import logging import re -from typing import Callable, Dict, Optional, Tuple +from typing import Callable, Dict, List, Optional, Tuple from lxml import etree @@ -146,10 +146,10 @@ class TestcaseExport: """Export testcases data into XML representation.""" def __init__( - self, testcases_data: dict, config: dict, transform_func: Optional[Callable] = None + self, testcases_data: List[dict], config: dict, transform_func: Optional[Callable] = None ): - self.testcases_data = testcases_data - self.config = config + self.testcases_data = testcases_data or [] + self.config = config or {} self._lookup_prop = "" self.testcases_transform = TestcaseTransform(config, transform_func) @@ -328,7 +328,9 @@ def _is_whitelisted(self, nodeid: str) -> bool: return False return True - def _testcase_element(self, parent_element: etree.Element, testcase_data: dict) -> None: + def _testcase_element( + self, parent_element: etree.Element, testcase_data: dict, records: list + ) -> None: """Add testcase XML element.""" nodeid = testcase_data.get("nodeid", "") if not self._is_whitelisted(nodeid): @@ -339,6 +341,10 @@ def _testcase_element(self, parent_element: etree.Element, testcase_data: dict) if not testcase_data: return + if testcase_data.get("ignored"): + LOGGER.debug("Skipping ignored node: %s", nodeid) + return + testcase_title = testcase_data.get("title") self._set_lookup_prop(testcase_data) if not self._check_lookup_prop(testcase_data): @@ -350,6 +356,7 @@ def _testcase_element(self, parent_element: etree.Element, testcase_data: dict) # make sure that ID is set even for "name" lookup method testcase_data["id"] = self._get_testcase_id(testcase_data) + records.append(testcase_data["id"]) attrs, custom_fields = self._classify_data(testcase_data) @@ -373,10 +380,12 @@ def _testcase_element(self, parent_element: etree.Element, testcase_data: dict) self._add_linked_items(testcase, testcase_data) def _fill_testcases(self, parent_element: etree.Element) -> None: - if not self.testcases_data: - raise NothingToDoException("Nothing to export") + records = [] # type: List[str] for testcase_data in self.testcases_data: - self._testcase_element(parent_element, testcase_data) + self._testcase_element(parent_element, testcase_data, records) + + if not records: + raise NothingToDoException("Nothing to export") def export(self) -> str: """Return testcases XML.""" diff --git a/dump2polarion/exporters/xunit_exporter.py b/dump2polarion/exporters/xunit_exporter.py index c10d600..0f8a48b 100644 --- a/dump2polarion/exporters/xunit_exporter.py +++ b/dump2polarion/exporters/xunit_exporter.py @@ -46,7 +46,7 @@ def __init__( ) -> None: self.testrun_id = testrun_id self.tests_records = tests_records - self.config = config + self.config = config or {} self._lookup_prop = "" self._transform_func = transform_func or transform_projects.get_xunit_transform(config) @@ -264,6 +264,10 @@ def _gen_testcase(self, parent_element: etree.Element, result: dict, records: di if not result: return + if result.get("ignored"): + LOGGER.debug("Skipping ignored testcase") + return + verdict = self._get_verdict(result) if not verdict: LOGGER.warning("Skipping testcase, verdict is missing or invalid") diff --git a/polarion_tools.yaml.template b/polarion_tools.yaml.template index a73a4c3..17691ee 100644 --- a/polarion_tools.yaml.template +++ b/polarion_tools.yaml.template @@ -20,8 +20,10 @@ default_fields: caseimportance: high caselevel: component caseposneg: positive + customerscenario: "" description: "" expectedResults: "" + ignored: false initialEstimate: "" linkedWorkItems: "" setup: "" @@ -41,6 +43,7 @@ custom_fields: - caseimportance - caselevel - caseposneg + - customerscenario - setup - subtype1 - subtype2 diff --git a/tests/test_testcase_exporter.py b/tests/test_testcase_exporter.py index f4fdedd..730dcfd 100644 --- a/tests/test_testcase_exporter.py +++ b/tests/test_testcase_exporter.py @@ -114,3 +114,14 @@ def test_no_requirements(self, config_cloudtp): with pytest.raises(NothingToDoException) as excinfo: testcase_exp.export() assert "Nothing to export" in str(excinfo.value) + + def test_all_ignored(self, config_cloudtp, captured_log): + testcase_exp = TestcaseExport( + [{"id": "foo", "title": "foo", "ignored": True}], + config_cloudtp, + transform_func=lambda arg: arg, + ) + with pytest.raises(NothingToDoException) as excinfo: + testcase_exp.export() + assert "Nothing to export" in str(excinfo.value) + assert "Skipping ignored node:" in captured_log.getvalue() diff --git a/tests/test_xunit_exporter.py b/tests/test_xunit_exporter.py index 3fa1f47..6ca1868 100644 --- a/tests/test_xunit_exporter.py +++ b/tests/test_xunit_exporter.py @@ -96,12 +96,25 @@ def test_e2e_noresults(self, records_ids): def test_e2e_missing_results(self): new_records = ImportedData(results=[], testrun=None) exporter = XunitExport( - "5_8_0_17", new_records, self.config_prop, transform_func=lambda arg: None + "5_8_0_17", new_records, self.config_prop, transform_func=lambda arg: arg ) with pytest.raises(NothingToDoException) as excinfo: exporter._fill_tests_results(None) assert "Nothing to export" in str(excinfo.value) + def test_e2e_all_ignored(self, captured_log): + new_records = ImportedData( + results=[{"title": "foo", "id": "foo", "verdict": "waiting", "ignored": True}], + testrun=None, + ) + exporter = XunitExport( + "5_8_0_17", new_records, self.config_prop, transform_func=lambda arg: arg + ) + with pytest.raises(NothingToDoException) as excinfo: + exporter.export() + assert "Nothing to export" in str(excinfo.value) + assert "Skipping ignored testcase" in captured_log.getvalue() + def test_e2e_ids_notransform(self, records_ids): exporter = XunitExport( "5_8_0_17", records_ids, self.config_prop, transform_func=lambda arg: arg