From 5cb60329eaef5cf683d96f56efaa4521a3c89f19 Mon Sep 17 00:00:00 2001 From: zixingdeng Date: Tue, 23 Sep 2025 13:14:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E6=8A=A5=E5=89=8D=E6=A0=A1=E6=AD=A3?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pytest/pyproject.toml | 2 +- pytest/src/testsolar_pytestx/executor.py | 24 ++++++++++++++++++++++++ pytest/testtool.yaml | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pytest/pyproject.toml b/pytest/pyproject.toml index e26bf76..8c51519 100644 --- a/pytest/pyproject.toml +++ b/pytest/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "testsolar-pytestx" -version = "0.1.54" +version = "0.1.55" description = "Pytest tool for TestSolar" authors = [ {name = "asiazhang2002", email = "asiazhang2002@gmail.com"}, diff --git a/pytest/src/testsolar_pytestx/executor.py b/pytest/src/testsolar_pytestx/executor.py index 96d9464..a5fda0b 100644 --- a/pytest/src/testsolar_pytestx/executor.py +++ b/pytest/src/testsolar_pytestx/executor.py @@ -133,6 +133,8 @@ def pytest_runtest_logreport(self, report: TestReport) -> None: logger.info(f"Skipped {file}:{line}: {reason}") test_result.Message = reason[:1000] + logger.info(f"{report.nodeid} setup result type: {result_type}") + elif report.when == "call": test_result.Steps.append( TestCaseStep( @@ -150,6 +152,8 @@ def pytest_runtest_logreport(self, report: TestReport) -> None: test_result.ResultType = result_type + logger.info(f"{report.nodeid} call result type: {result_type}") + elif report.when == "teardown": test_result.Steps.append( TestCaseStep( @@ -163,8 +167,24 @@ def pytest_runtest_logreport(self, report: TestReport) -> None: if not test_result.is_final(): test_result.ResultType = result_type + logger.info(f"{report.nodeid} teardown result type: {result_type}") + logger.info(f"E {report.nodeid} log report") + def _correct_result_type( + self, steps: List[TestCaseStep], original_result_type: ResultType, testcase_name: str + ) -> ResultType: + """校正测试结果类型""" + result_type = original_result_type + for step in steps: + if step.ResultType == ResultType.FAILED and result_type == ResultType.SUCCEED: + logger.info( + f"{testcase_name} result type corrected to FAILED due to failed step: {step.Title}" + ) + result_type = ResultType.FAILED + break + return result_type + def pytest_runtest_logfinish(self, nodeid: str, location: Any) -> None: """ Called at the end of running the runtest protocol for a single item. @@ -174,6 +194,10 @@ def pytest_runtest_logfinish(self, nodeid: str, location: Any) -> None: test_result = self.testdata[testcase_name] test_result.EndTime = datetime.utcnow() + # 上报前预先校正一遍测试结果 + test_result.ResultType = self._correct_result_type( + test_result.Steps, test_result.ResultType, testcase_name + ) self.testcase_count += 1 logger.info( f"Testcase {nodeid} finished with result type {test_result.ResultType}, total {self.testcase_count} testcases complete" diff --git a/pytest/testtool.yaml b/pytest/testtool.yaml index c6996b9..5086bd1 100644 --- a/pytest/testtool.yaml +++ b/pytest/testtool.yaml @@ -2,7 +2,7 @@ schemaVersion: 1.0 name: pytest nameZh: pytest自动化测试 lang: python -version: '0.1.54' +version: '0.1.55' langType: INTERPRETED description: |- pytest是一个成熟的全功能Python测试工具,可以帮助您编写更好的程序。此测试工具允许您在TestSolar上运行pytest。