From ced8c1c6fc12e68eb8d11c150b96c8cdc2ae6bee Mon Sep 17 00:00:00 2001 From: Ivan Diaz Date: Tue, 8 Nov 2022 16:06:47 -0800 Subject: [PATCH] Implemented Yaml reader alongside Xunit, Junit, and Trx. --- .../reporter/formats/__init__.py | 4 +- .../azure-pipelines/reporter/formats/yaml.py | 60 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/Microsoft.DotNet.Helix/Sdk/tools/azure-pipelines/reporter/formats/yaml.py diff --git a/src/Microsoft.DotNet.Helix/Sdk/tools/azure-pipelines/reporter/formats/__init__.py b/src/Microsoft.DotNet.Helix/Sdk/tools/azure-pipelines/reporter/formats/__init__.py index 5a0077bee68..53249adef1e 100644 --- a/src/Microsoft.DotNet.Helix/Sdk/tools/azure-pipelines/reporter/formats/__init__.py +++ b/src/Microsoft.DotNet.Helix/Sdk/tools/azure-pipelines/reporter/formats/__init__.py @@ -3,10 +3,12 @@ from .xunit import XUnitFormat from .junit import JUnitFormat from .trx import TRXFormat +from .yaml import YAMLFormat all_formats = [ XUnitFormat(), JUnitFormat(), - TRXFormat() + TRXFormat(), + YAMLFormat() ] # type: List[ResultFormat] diff --git a/src/Microsoft.DotNet.Helix/Sdk/tools/azure-pipelines/reporter/formats/yaml.py b/src/Microsoft.DotNet.Helix/Sdk/tools/azure-pipelines/reporter/formats/yaml.py new file mode 100644 index 00000000000..8643d2cae65 --- /dev/null +++ b/src/Microsoft.DotNet.Helix/Sdk/tools/azure-pipelines/reporter/formats/yaml.py @@ -0,0 +1,60 @@ +import yaml + +from .result_format import ResultFormat +from helix.public import TestResult, TestResultAttachment + +class YAMLFormat(ResultFormat): + + def __init__(self): + super(YAMLFormat, self).__init__() + pass + + @property + def name(self): + return 'yaml' + + @property + def acceptable_file_suffixes(self): + yield 'testResults.yml' + yield 'test-results.yml' + yield 'test_results.yml' + + # Work in Progress :) + def read_results(self, path): + contents = None + with open(path) as fh: + contents = yaml.safe_load(fh) + + results = contents.get("assemblies").get("assembly").get("collection").get("tests") + + for test in results: + name = test.get("name") + type_name = test.get("type") + method = test.get("method") + time = float(test.get("time")) + result = test.get("result") + exception_type = None + failure_message = None + stack_trace = None + skip_reason = None + attachments = [] + + failure_element = test.find("failure") + + if failure_element is not None: + exception_type = failure_element.get("exception-type") + failure_message = failure_element.find("message") + stack_trace = failure_element.find("stack-trace") + + output_element = test.find("output") + + if output_element is not None: + attachments.append(TestResultAttachment( + name=u"Console_Output.log", + text=output_element, + )) + + skip_reason = test.find("reason") + res = TestResult(name, u'yaml', type_name, method, time, result, exception_type, + failure_message, stack_trace, skip_reason, attachments) + yield res