Skip to content

Commit

Permalink
Improve parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
vmilosevic committed Nov 29, 2024
1 parent eea8fd5 commit fb0d01f
Show file tree
Hide file tree
Showing 6 changed files with 1,214 additions and 7 deletions.
20 changes: 14 additions & 6 deletions .github/actions/collect_data/src/parsers/python_unittest_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,23 @@ def get_tests(test_report_path):
dict_data = xmltodict.parse(data)
previous_test_end_ts = None

# Workaround: If test info does not have timestamp, use current time
if "@timestamp" not in dict_data["testsuites"]["testsuite"][0]["testcase"][0]:
previous_test_end_ts = datetime.now().isoformat()
logger.warning("Timestamp not found in test report. Using current time.")
testsuites = dict_data["testsuites"]["testsuite"]
if not isinstance(testsuites, list):
testsuites = [testsuites]

if "@file" not in dict_data["testsuites"]["testsuite"][0]["testcase"][0]:
# Workaround: If testcases does not have timestamp, try using timestamp from testsuite and add duration
if "@timestamp" not in testsuites[0]["testcase"][0]:
logger.warning("Timestamp not found in test report, using testsuite timestamp")
previous_test_end_ts = testsuites[0].get("@timestamp", None)
# if testsuites does not have timestamp, use current time
if not previous_test_end_ts:
logger.warning("Timestamp not found in testsuite, using current time")
previous_test_end_ts = datetime.now().isoformat()

if "@file" not in testsuites[0]["testcase"][0]:
logger.warning("Filepath not found in test report.")

for testsuite in dict_data["testsuites"]["testsuite"]:
for testsuite in testsuites:

# testcases can be dict or list
testcases = testsuite["testcase"]
Expand Down
7 changes: 6 additions & 1 deletion .github/actions/collect_data/src/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def parse_file(filepath: str) -> List[Test]:
filepath = str(filepath)
for parser in parsers:
if parser.can_parse(filepath):
return parser.parse(filepath)
try:
return parser.parse(filepath)
except Exception as e:
logger.error(
f"Error parsing file: {filepath} using parser: {type(parser).__name__}, trying next parser."
)
logger.error(f"No parser available for file: {filepath}")
return []
Loading

0 comments on commit fb0d01f

Please sign in to comment.