!299 修复部分测试套生成报告异常的bug

Merge pull request !299 from liguangjie/master
This commit is contained in:
openharmony_ci 2024-10-11 06:45:03 +00:00 committed by Gitee
commit cda8083354
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 20 additions and 10 deletions

View File

@ -65,6 +65,9 @@ class OHJSUnitTestParser(IParser):
self.result_data = ""
self.listener_result_info_tuple = None
# message from test output, the 'TestFinished-ResultMsg'
self.__test_finish_result_msg = ""
def get_suite_name(self):
return self.suites_name
@ -257,7 +260,8 @@ class OHJSUnitTestParser(IParser):
if self._is_target_listener(listener):
self._cal_result(listener)
suite = copy.copy(suite_result)
listener.__ended__(LifeCycle.TestSuites, suite, suites_name=self.suites_name)
listener.__ended__(LifeCycle.TestSuites, suite, suites_name=self.suites_name,
message=self.__test_finish_result_msg)
def _cal_result(self, report_listener):
result_len = len(report_listener.result) # List[Tuple]
@ -302,7 +306,7 @@ class OHJSUnitTestParser(IParser):
test_result = self.state_machine.test(reset=True)
test_result.test_class = test_des.class_name
test_result.test_name = test_des.test_name
test_result.stacktrace = "error_msg: mark blocked"
test_result.stacktrace = self.__test_finish_result_msg or "error_msg: mark blocked"
test_result.num_tests = 1
test_result.run_time = 0
test_result.current = \
@ -337,7 +341,7 @@ class OHJSUnitTestParser(IParser):
test_result = self.state_machine.test(reset=True)
test_result.test_class = test.class_name
test_result.test_name = test.test_name
test_result.stacktrace = "error_msg: mark blocked"
test_result.stacktrace = self.__test_finish_result_msg or "error_msg: mark blocked"
test_result.num_tests = 1
test_result.run_time = 0
test_result.current = self.state_machine.running_test_index + 1
@ -361,6 +365,7 @@ class OHJSUnitTestParser(IParser):
def _handle_result_msg(self, line):
if OHJSUnitItemConstants.APP_DIED.value in line:
self.__test_finish_result_msg = line.replace(OHJSUnitPrefixes.TEST_FINISHED_RESULT_MSG.value, '')
test_result = self.state_machine.test()
suite = self.state_machine.suite()
if not test_result.is_completed:
@ -433,6 +438,9 @@ class OHJSWorkParser(IParser):
self.temp_class = None
self.temp_test = None
# message from test output, the 'TestFinished-ResultMsg'
self.__test_finish_result_msg = ""
def __process__(self, lines):
for line in lines:
line = str(line).strip().rstrip("\r")
@ -565,6 +573,7 @@ class OHJSWorkParser(IParser):
def _handle_result_msg(self, line):
if OHJSUnitItemConstants.APP_DIED.value in line:
self.__test_finish_result_msg = line.replace(OHJSUnitPrefixes.TEST_FINISHED_RESULT_MSG.value, '')
test_result = self.state_machine.test()
suite = self.state_machine.suite()
if not test_result.is_completed:
@ -642,7 +651,8 @@ class OHJSWorkParser(IParser):
if not suite_result.is_completed:
self.handle_suite_end()
self.state_machine.pop_last_suite()
target_listener.__ended__(LifeCycle.TestSuites, suite_result, suites_name=self.suites_name)
target_listener.__ended__(LifeCycle.TestSuites, suite_result, suites_name=self.suites_name,
message=self.__test_finish_result_msg)
def handle_suite_result(self, target_listener):
for suite_name, test_info_list in self.all_result_dict.items():
@ -678,7 +688,7 @@ class OHJSWorkParser(IParser):
test_result = self.state_machine.test(reset=True)
test_result.test_class = suite_name
test_result.test_name = case_name
test_result.stacktrace = "error_msg: mark blocked"
test_result.stacktrace = self.__test_finish_result_msg or "error_msg: mark blocked"
test_result.num_tests = 1
test_result.run_time = 0
test_result.current = \
@ -713,4 +723,3 @@ class OHJSWorkParser(IParser):
return ResultCode.PASSED.value
else:
return ResultCode.FAILED.value

View File

@ -21,14 +21,14 @@ import re
import stat
import uuid
from abc import ABC
from abc import abstractmethod
from _core.plugin import Plugin
from _core.plugin import get_plugin
from _core.constants import TestType
from _core.executor.bean import SuiteResult
from _core.executor.bean import CaseResult
from _core.executor.bean import SuiteResult
from _core.executor.bean import SuitesResult
from _core.interface import LifeCycle
from _core.interface import IListener
from _core.report.suite_reporter import SuiteReporter
@ -205,8 +205,9 @@ class ReportEventListener(AbsReportListener, ABC):
if not kwargs.get("suite_report", False):
result_dir = os.path.join(self.report_path, "result")
os.makedirs(result_dir, exist_ok=True)
message = ""
if test_result:
message = kwargs.get("message", "")
# 有的场景传SuiteResult对象进来导致报错需要增加实例判断
if isinstance(test_result, SuitesResult):
message = test_result.stacktrace
suites_name = test_result.suites_name
else: