Skip to content

增加算子库单元测试清单#46

Open
ghangz wants to merge 2 commits into
MetaX-MACA:mainfrom
ghangz:mengz/mcoplib-unit-test-inventory
Open

增加算子库单元测试清单#46
ghangz wants to merge 2 commits into
MetaX-MACA:mainfrom
ghangz:mengz/mcoplib-unit-test-inventory

Conversation

@ghangz

@ghangz ghangz commented Jun 10, 2026

Copy link
Copy Markdown

这次改动补上了算子库单元测试清单,主要是为了解决算子库构建和诊断流程里相关信息不够集中、人工整理成本较高的问题,让日常排查、验证和结果归档更直接。

实现上补充了对应工具或脚本逻辑,补上了对应测试,同时尽量保持现有用法不变,避免影响已有流程。

这一分支已经在沐曦算力环境完成实际验证,相关检查均已通过,现提交合入。

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tools/unit_test_inventory.py Outdated
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_"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

在 Python 的 ast 模块中,ast.AsyncFunctionDef(用于异步函数 async def)和 ast.FunctionDef(用于普通函数 def)是平级的。当前的实现仅检查了 ast.FunctionDef,这会导致遗漏使用 async def 定义的异步测试函数(例如在使用 pytest-asynciounittest.IsolatedAsyncioTestCase 时)。

建议同时匹配这两种类型,以确保能够正确扫描到所有的异步测试函数。

Suggested change
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_"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant