增加算子库单元测试清单#46
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new script tools/unit_test_inventory.py to export unit test metadata as JSON by parsing test files with Python's ast module, along with a corresponding unit test. Feedback suggests extending the AST node check to include ast.AsyncFunctionDef so that asynchronous test functions (defined with async def) are also correctly inventoried.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| tree = ast.parse(path.read_text(encoding="utf-8", errors="replace")) | ||
| except SyntaxError as exc: | ||
| return [], f"{exc.__class__.__name__}: {exc}" | ||
| tests = sorted(node.name for node in ast.walk(tree) if isinstance(node, ast.FunctionDef) and node.name.startswith("test_")) |
There was a problem hiding this comment.
在 Python 的 ast 模块中,ast.AsyncFunctionDef(用于异步函数 async def)和 ast.FunctionDef(用于普通函数 def)是平级的。当前的实现仅检查了 ast.FunctionDef,这会导致遗漏使用 async def 定义的异步测试函数(例如在使用 pytest-asyncio 或 unittest.IsolatedAsyncioTestCase 时)。
建议同时匹配这两种类型,以确保能够正确扫描到所有的异步测试函数。
| tests = sorted(node.name for node in ast.walk(tree) if isinstance(node, ast.FunctionDef) and node.name.startswith("test_")) | |
| tests = sorted(node.name for node in ast.walk(tree) if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)) and node.name.startswith("test_")) |
这次改动补上了算子库单元测试清单,主要是为了解决算子库构建和诊断流程里相关信息不够集中、人工整理成本较高的问题,让日常排查、验证和结果归档更直接。
实现上补充了对应工具或脚本逻辑,补上了对应测试,同时尽量保持现有用法不变,避免影响已有流程。
这一分支已经在沐曦算力环境完成实际验证,相关检查均已通过,现提交合入。