Skip to content

Commit 5cb6032

Browse files
committed
上报前校正用例结果
1 parent c5f4d09 commit 5cb6032

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

‎pytest/pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "testsolar-pytestx"
3-
version = "0.1.54"
3+
version = "0.1.55"
44
description = "Pytest tool for TestSolar"
55
authors = [
66
{name = "asiazhang2002", email = "asiazhang2002@gmail.com"},

‎pytest/src/testsolar_pytestx/executor.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ def pytest_runtest_logreport(self, report: TestReport) -> None:
133133
logger.info(f"Skipped {file}:{line}: {reason}")
134134
test_result.Message = reason[:1000]
135135

136+
logger.info(f"{report.nodeid} setup result type: {result_type}")
137+
136138
elif report.when == "call":
137139
test_result.Steps.append(
138140
TestCaseStep(
@@ -150,6 +152,8 @@ def pytest_runtest_logreport(self, report: TestReport) -> None:
150152

151153
test_result.ResultType = result_type
152154

155+
logger.info(f"{report.nodeid} call result type: {result_type}")
156+
153157
elif report.when == "teardown":
154158
test_result.Steps.append(
155159
TestCaseStep(
@@ -163,8 +167,24 @@ def pytest_runtest_logreport(self, report: TestReport) -> None:
163167
if not test_result.is_final():
164168
test_result.ResultType = result_type
165169

170+
logger.info(f"{report.nodeid} teardown result type: {result_type}")
171+
166172
logger.info(f"E {report.nodeid} log report")
167173

174+
def _correct_result_type(
175+
self, steps: List[TestCaseStep], original_result_type: ResultType, testcase_name: str
176+
) -> ResultType:
177+
"""校正测试结果类型"""
178+
result_type = original_result_type
179+
for step in steps:
180+
if step.ResultType == ResultType.FAILED and result_type == ResultType.SUCCEED:
181+
logger.info(
182+
f"{testcase_name} result type corrected to FAILED due to failed step: {step.Title}"
183+
)
184+
result_type = ResultType.FAILED
185+
break
186+
return result_type
187+
168188
def pytest_runtest_logfinish(self, nodeid: str, location: Any) -> None:
169189
"""
170190
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:
174194

175195
test_result = self.testdata[testcase_name]
176196
test_result.EndTime = datetime.utcnow()
197+
# 上报前预先校正一遍测试结果
198+
test_result.ResultType = self._correct_result_type(
199+
test_result.Steps, test_result.ResultType, testcase_name
200+
)
177201
self.testcase_count += 1
178202
logger.info(
179203
f"Testcase {nodeid} finished with result type {test_result.ResultType}, total {self.testcase_count} testcases complete"

‎pytest/testtool.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ schemaVersion: 1.0
22
name: pytest
33
nameZh: pytest自动化测试
44
lang: python
5-
version: '0.1.54'
5+
version: '0.1.55'
66
langType: INTERPRETED
77
description: |-
88
pytest是一个成熟的全功能Python测试工具,可以帮助您编写更好的程序。此测试工具允许您在TestSolar上运行pytest。

0 commit comments

Comments
 (0)