Skip to content

Commit

Permalink
feat: add support for ignored testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoura committed Apr 2, 2020
1 parent 52715db commit 0c94415
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
25 changes: 17 additions & 8 deletions dump2polarion/exporters/testcases_exporter.py
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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)

Expand All @@ -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."""
Expand Down
6 changes: 5 additions & 1 deletion dump2polarion/exporters/xunit_exporter.py
Expand Up @@ -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)

Expand Down Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions polarion_tools.yaml.template
Expand Up @@ -20,8 +20,10 @@ default_fields:
caseimportance: high
caselevel: component
caseposneg: positive
customerscenario: ""
description: ""
expectedResults: ""
ignored: false
initialEstimate: ""
linkedWorkItems: ""
setup: ""
Expand All @@ -41,6 +43,7 @@ custom_fields:
- caseimportance
- caselevel
- caseposneg
- customerscenario
- setup
- subtype1
- subtype2
Expand Down
11 changes: 11 additions & 0 deletions tests/test_testcase_exporter.py
Expand Up @@ -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()
15 changes: 14 additions & 1 deletion tests/test_xunit_exporter.py
Expand Up @@ -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
Expand Down

0 comments on commit 0c94415

Please sign in to comment.