diff --git a/pytest/pyproject.toml b/pytest/pyproject.toml index 41c559f..7d9317b 100644 --- a/pytest/pyproject.toml +++ b/pytest/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "testsolar-pytestx" -version = "0.1.73" +version = "0.1.75" description = "Pytest tool for TestSolar" authors = [ {name = "asiazhang2002", email = "asiazhang2002@gmail.com"}, diff --git a/pytest/src/testsolar_pytestx/parser.py b/pytest/src/testsolar_pytestx/parser.py index 50e36e5..1f55616 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 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 + + # 检查类的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 "" 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": "[]", diff --git a/pytest/testtool.yaml b/pytest/testtool.yaml index bad4adf..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.73' +version: '0.1.75' langType: INTERPRETED description: |- pytest是一个成熟的全功能Python测试工具,可以帮助您编写更好的程序。此测试工具允许您在TestSolar上运行pytest。