From 4c6e600e76c54b96b09b4fe8b060b62afd5a8abe Mon Sep 17 00:00:00 2001 From: ambzhang <450145249@qq.com> Date: Thu, 15 Jan 2026 17:51:09 +0800 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=94=B6=E9=9B=86=E5=99=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 重构collector.py中的测试收集流程以提高效率和可读性。 --- pytest/src/testsolar_pytestx/parser.py | 19 +++++++++++++++++-- pytest/tests/test_parser.py | 3 ++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pytest/src/testsolar_pytestx/parser.py b/pytest/src/testsolar_pytestx/parser.py index 50e36e5..1700cdd 100644 --- a/pytest/src/testsolar_pytestx/parser.py +++ b/pytest/src/testsolar_pytestx/parser.py @@ -22,11 +22,26 @@ def _get_desc(item: Item) -> str: + # 优先检查类的docstring(HttpRunner测试用例) + try: + if hasattr(item, "cls") and item.cls and item.cls.__doc__: + class_doc = item.cls.__doc__.strip() + if class_doc: + return str(class_doc) + except (AttributeError, TypeError): + pass + + # 然后检查函数的docstring try: doc = item.function.__doc__ # type: ignore + if doc: + doc_str = str(doc).strip() + if doc_str and doc_str != "main entrance, discovered by pytest": + return doc_str except AttributeError: - return "" - return str(doc).strip() if doc else "" + pass + + return "" def _iter_markers(item: Item) -> List[Mark]: diff --git a/pytest/tests/test_parser.py b/pytest/tests/test_parser.py index 5754e22..14dc0df 100644 --- a/pytest/tests/test_parser.py +++ b/pytest/tests/test_parser.py @@ -47,10 +47,11 @@ def test_parse_case_attributes(): coding_testcase_id: 123,456 """ item.own_markers = [] + item.cls = None # 确保没有类级别的docstring comment_fields = ["description", "owner", "coding_testcase_id"] expected = { - "description": "This is a test function", + "description": "This is a test function", # 从注释中解析出的description字段值 "owner": "test_owner", "coding_testcase_id": '["123", "456"]', "tags": "[]", From 6aa073ce46fb199d6d3a892e332f38016ba8f968 Mon Sep 17 00:00:00 2001 From: ambzhang <450145249@qq.com> Date: Thu, 15 Jan 2026 17:53:08 +0800 Subject: [PATCH 2/4] chore: update project configuration files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新 pyproject.toml 和 testtool.yaml 配置文件。 --- pytest/pyproject.toml | 2 +- pytest/testtool.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pytest/pyproject.toml b/pytest/pyproject.toml index 41c559f..d733ee9 100644 --- a/pytest/pyproject.toml +++ b/pytest/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "testsolar-pytestx" -version = "0.1.73" +version = "0.1.74" description = "Pytest tool for TestSolar" authors = [ {name = "asiazhang2002", email = "asiazhang2002@gmail.com"}, diff --git a/pytest/testtool.yaml b/pytest/testtool.yaml index bad4adf..d1a1c28 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.73' +version: '0.1.74' langType: INTERPRETED description: |- pytest是一个成熟的全功能Python测试工具,可以帮助您编写更好的程序。此测试工具允许您在TestSolar上运行pytest。 From 4fb0a666c7a58280ea6a8bf241f5f3c7ae102805 Mon Sep 17 00:00:00 2001 From: ambzhang <450145249@qq.com> Date: Thu, 15 Jan 2026 18:06:18 +0800 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E5=99=A8=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 改进解析器代码结构,提升可读性和维护性。 --- pytest/src/testsolar_pytestx/parser.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pytest/src/testsolar_pytestx/parser.py b/pytest/src/testsolar_pytestx/parser.py index 1700cdd..1f55616 100644 --- a/pytest/src/testsolar_pytestx/parser.py +++ b/pytest/src/testsolar_pytestx/parser.py @@ -22,16 +22,7 @@ def _get_desc(item: Item) -> str: - # 优先检查类的docstring(HttpRunner测试用例) - try: - if hasattr(item, "cls") and item.cls and item.cls.__doc__: - class_doc = item.cls.__doc__.strip() - if class_doc: - return str(class_doc) - except (AttributeError, TypeError): - pass - - # 然后检查函数的docstring + # 优先检查函数的docstring try: doc = item.function.__doc__ # type: ignore if doc: @@ -41,6 +32,15 @@ def _get_desc(item: Item) -> str: except AttributeError: pass + # 检查类的docstring(HttpRunner测试用例) + try: + if hasattr(item, "cls") and item.cls and item.cls.__doc__: + class_doc = item.cls.__doc__.strip() + if class_doc: + return str(class_doc) + except (AttributeError, TypeError): + pass + return "" From 5dd6bd3ba8685b2ada451ef3b6b8b9b7343c9919 Mon Sep 17 00:00:00 2001 From: ambzhang <450145249@qq.com> Date: Thu, 15 Jan 2026 18:07:29 +0800 Subject: [PATCH 4/4] chore: update project config files Update pyproject.toml and testtool.yaml for project configuration changes. --- pytest/pyproject.toml | 2 +- pytest/testtool.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pytest/pyproject.toml b/pytest/pyproject.toml index d733ee9..7d9317b 100644 --- a/pytest/pyproject.toml +++ b/pytest/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "testsolar-pytestx" -version = "0.1.74" +version = "0.1.75" description = "Pytest tool for TestSolar" authors = [ {name = "asiazhang2002", email = "asiazhang2002@gmail.com"}, diff --git a/pytest/testtool.yaml b/pytest/testtool.yaml index d1a1c28..13d4e65 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.74' +version: '0.1.75' langType: INTERPRETED description: |- pytest是一个成熟的全功能Python测试工具,可以帮助您编写更好的程序。此测试工具允许您在TestSolar上运行pytest。