Skip to content

Commit 5407209

Browse files
authored
Merge pull request #108 from OpenTestSolar/dev/add_testx_id
feat: 新增对 coding_testcase_id 标记的处理
2 parents c5f4d09 + b33b7e2 commit 5407209

6 files changed

Lines changed: 44 additions & 5 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/parser.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ def parse_case_attributes(item: Item, comment_fields: Optional[List[str]] = None
4141
extra_attr[key] = mark.args[0][key]
4242
attr_list.append(extra_attr)
4343
attributes["extra_attributes"] = json.dumps(attr_list)
44+
elif mark.name == "coding_testcase_id":
45+
case_data_name = item.name.split("[")[1][:-1]
46+
for data_name in mark.args[0]:
47+
if data_name == case_data_name:
48+
attributes["coding_testcase_id"] = mark.args[0][data_name]
49+
4450
attributes["tags"] = json.dumps(tags)
4551
return attributes
4652

‎pytest/testdata/test_coding_id.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
3+
import pytest
4+
5+
6+
@pytest.mark.parametrize("test_input,expected", [("3+5", 8), ("2+4", 6), ("6*9", 42)])
7+
@pytest.mark.coding_testcase_id({"2+4-6": "123", "6*9-42": "456", "3+5-8": "789"})
8+
def test_eval(test_input, expected):
9+
assert eval(test_input) == expected

‎pytest/tests/test_collector.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,28 @@ def test_collect_testcases_with_emoji(self):
224224
re.Tests[0].Name,
225225
"test_emoji_data_drive.py?test_emoji_data_drive_name/[😄]",
226226
)
227+
228+
def test_collect_testcases_with_coding_testcase_id(self):
229+
entry = EntryParam(
230+
TaskId="aa",
231+
ProjectPath=self.testdata_dir,
232+
TestSelectors=[
233+
"test_coding_id.py",
234+
],
235+
FileReportPath="",
236+
)
237+
238+
pipe_io = io.BytesIO()
239+
collect_testcases(entry, pipe_io)
240+
pipe_io.seek(0)
241+
242+
re = read_load_result(pipe_io)
243+
re.Tests.sort(key=lambda x: x.Name)
244+
re.LoadErrors.sort(key=lambda x: x.name)
245+
self.assertEqual(len(re.Tests), 3)
246+
self.assertEqual(len(re.LoadErrors), 0)
247+
self.assertEqual(
248+
re.Tests[0].Name,
249+
'test_coding_id.py?test_eval/[2+4-6]',
250+
)
251+
self.assertEqual(re.Tests[1].Attributes['coding_testcase_id'], '789')

‎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。

‎pytest/uv.lock‎

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)