Skip to content

Commit 1ae630f

Browse files
authored
Merge pull request #115 from OpenTestSolar/dev/add_parse_httprunner_desc
refactor: 优化测试收集器逻辑
2 parents 432e3fc + 5dd6bd3 commit 1ae630f

4 files changed

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

‎pytest/src/testsolar_pytestx/parser.py‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,26 @@
2222

2323

2424
def _get_desc(item: Item) -> str:
25+
# 优先检查函数的docstring
2526
try:
2627
doc = item.function.__doc__ # type: ignore
28+
if doc:
29+
doc_str = str(doc).strip()
30+
if doc_str and doc_str != "main entrance, discovered by pytest":
31+
return doc_str
2732
except AttributeError:
28-
return ""
29-
return str(doc).strip() if doc else ""
33+
pass
34+
35+
# 检查类的docstring(HttpRunner测试用例)
36+
try:
37+
if hasattr(item, "cls") and item.cls and item.cls.__doc__:
38+
class_doc = item.cls.__doc__.strip()
39+
if class_doc:
40+
return str(class_doc)
41+
except (AttributeError, TypeError):
42+
pass
43+
44+
return ""
3045

3146

3247
def _iter_markers(item: Item) -> List[Mark]:

‎pytest/tests/test_parser.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ def test_parse_case_attributes():
4747
coding_testcase_id: 123,456
4848
"""
4949
item.own_markers = []
50+
item.cls = None # 确保没有类级别的docstring
5051

5152
comment_fields = ["description", "owner", "coding_testcase_id"]
5253
expected = {
53-
"description": "This is a test function",
54+
"description": "This is a test function", # 从注释中解析出的description字段值
5455
"owner": "test_owner",
5556
"coding_testcase_id": '["123", "456"]',
5657
"tags": "[]",

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

0 commit comments

Comments
 (0)