Skip to content

Commit f0825d7

Browse files
authored
fix:修复空变量 (#71)
* 修复空变量 * 新增版本 * 增加用例 * fix
1 parent f2f0dc5 commit f0825d7

4 files changed

Lines changed: 122 additions & 3 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.23"
3+
version = "0.1.24"
44
description = "Pytest tool for TestSolar"
55
authors = [
66
{name = "asiazhang2002", email = "asiazhang2002@gmail.com"},

‎pytest/src/testsolar_pytestx/extend/allure_extend.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def generate_allure_results(test_data: Dict[str, TestResult], file_name: str) ->
7777
allure_data = from_dict(data_class=AllureData, data=json.loads(fp.read()))
7878
full_name = allure_data.fullName.replace("#", ".")
7979
for testcase_name in test_data.keys():
80+
step_info: List[TestCaseStep] = []
8081
testcase_format_name = ".".join(
8182
testcase_name.replace(".py?", os.sep).split(os.sep)
8283
)

‎pytest/tests/test_run_allure.py‎

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,132 @@
11
import io
22
import os
3+
import pytest
34
from pathlib import Path
45
from unittest import TestCase
6+
from unittest.mock import patch, mock_open
7+
from datetime import datetime
58

6-
from testsolar_testtool_sdk.model.testresult import ResultType
79
from testsolar_testtool_sdk.pipe_reader import read_test_result
10+
from testsolar_testtool_sdk.model.test import TestCase as TestSolar_TestCase
11+
from testsolar_testtool_sdk.model.testresult import (
12+
TestResult,
13+
ResultType,
14+
)
15+
16+
from testsolar_pytestx.extend.allure_extend import (
17+
generate_allure_results,
18+
gen_allure_step_info,
19+
format_allure_time,
20+
ResultType,
21+
Step,
22+
)
823

924
from run import run_testcases_from_args
1025

1126

27+
allure_json = """
28+
{
29+
"name": "test_case_1",
30+
"status": "passed",
31+
"start": 1622547800000,
32+
"stop": 1622547900000,
33+
"uuid": "12345",
34+
"historyId": "67890",
35+
"testCaseId": "abcde",
36+
"fullName": "test_module.test_case_1",
37+
"steps": [
38+
{
39+
"name": "step1",
40+
"status": "passed",
41+
"start": 1622547800000,
42+
"stop": 1622547810000,
43+
"parameters": [],
44+
"steps": [],
45+
"statusDetails": null
46+
},
47+
{
48+
"name": "step2",
49+
"status": "skipped",
50+
"start": 1622547800000,
51+
"stop": 1622547810000,
52+
"parameters": [],
53+
"steps": [],
54+
"statusDetails": null
55+
},
56+
{
57+
"name": "step3",
58+
"status": "failed",
59+
"start": 1622547800000,
60+
"stop": 1622547810000,
61+
"parameters": [],
62+
"steps": [],
63+
"statusDetails":
64+
{
65+
"message": "step3 failed",
66+
"trace": "trace info"
67+
}
68+
}
69+
],
70+
"labels": []
71+
}
72+
"""
73+
74+
75+
@pytest.fixture
76+
def test_data():
77+
return {
78+
"test_module.test_case_1": TestResult(
79+
Test=TestSolar_TestCase(Name="test_module.test_case_1", Attributes={}),
80+
StartTime=datetime.now(),
81+
ResultType=ResultType.SUCCEED,
82+
Message="",
83+
Steps=[],
84+
),
85+
"test_module.test_case_2": TestResult(
86+
Test=TestSolar_TestCase(Name="test_module.test_case_2", Attributes={}),
87+
StartTime=datetime.now(),
88+
ResultType=ResultType.SUCCEED,
89+
Message="",
90+
Steps=[],
91+
),
92+
}
93+
94+
95+
class TestAllureResults:
96+
def test_generate_allure_results(self, test_data):
97+
with patch("builtins.open", mock_open(read_data=allure_json)):
98+
generate_allure_results(test_data, "dummy_file.json")
99+
100+
assert len(test_data["test_module.test_case_1"].Steps) == 3
101+
assert test_data["test_module.test_case_1"].Steps[0].Title == "1: step1"
102+
assert (
103+
test_data["test_module.test_case_1"].Steps[0].ResultType
104+
== ResultType.SUCCEED
105+
)
106+
107+
def test_gen_allure_step_info(self):
108+
steps = [
109+
Step(
110+
name="step1",
111+
status="passed",
112+
start=1622547800000,
113+
stop=1622547810000,
114+
parameters=[],
115+
steps=[],
116+
statusDetails=None,
117+
)
118+
]
119+
result = gen_allure_step_info(steps)
120+
assert len(result) == 1
121+
assert result[0].Title == "1: step1"
122+
assert result[0].ResultType == ResultType.SUCCEED
123+
124+
def test_format_allure_time(self):
125+
timestamp = 1622547800000
126+
result = format_allure_time(timestamp)
127+
assert result == datetime.fromtimestamp(timestamp / 1000)
128+
129+
12130
class TestExecuteEntry(TestCase):
13131
testdata_dir: str = str(
14132
Path(__file__).parent.parent.absolute().joinpath("testdata")

‎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.23'
5+
version: '0.1.24'
66
langType: INTERPRETED
77
description: |-
88
pytest是一个成熟的全功能Python测试工具,可以帮助您编写更好的程序。此测试工具允许您在TestSolar上运行pytest。

0 commit comments

Comments
 (0)