增加算子测试框架分组计划#7
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a tool, tools/pytest_group_plan.py, to group pytest commands by subdirectories under the tests directory, along with its corresponding unit tests in tests/test_pytest_group_plan.py. The reviewer provided valuable feedback pointing out two potential FileNotFoundError exceptions: one if the tests directory does not exist when scanning for test files, and another if the parent directories for the specified --output path do not exist. Both comments include actionable code suggestions to improve the robustness of the script.
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.
| for path in sorted((root / "tests").rglob("test_*.py")): | ||
| rel = path.relative_to(root).as_posix() | ||
| parts = path.relative_to(root / "tests").parts | ||
| group = parts[0] if len(parts) > 1 else "root" | ||
| groups[group].append(rel) |
There was a problem hiding this comment.
如果 root / "tests" 目录不存在,在对 (root / "tests").rglob("test_*.py") 进行迭代(如 sorted)时会抛出 FileNotFoundError 异常。建议在扫描前先检查该目录是否存在且为目录,以提高代码的健壮性。此外,将 root / "tests" 提取为局部变量 tests_dir 也可以减少重复代码,提升可读性。
tests_dir = root / "tests"
if tests_dir.is_dir():
for path in sorted(tests_dir.rglob("test_*.py")):
rel = path.relative_to(root).as_posix()
parts = path.relative_to(tests_dir).parts
group = parts[0] if len(parts) > 1 else "root"
groups[group].append(rel)| if args.output: | ||
| args.output.write_text(text + "\n", encoding="utf-8") |
There was a problem hiding this comment.
如果指定的 --output 路径包含不存在的父级目录(例如 --output build/report.json),直接调用 write_text 会抛出 FileNotFoundError。建议在写入前先创建父级目录。
| if args.output: | |
| args.output.write_text(text + "\n", encoding="utf-8") | |
| if args.output: | |
| args.output.parent.mkdir(parents=True, exist_ok=True) | |
| args.output.write_text(text + "\n", encoding="utf-8") |
这次改动补上了算子测试框架分组计划,主要是为了解决算子测试与维护流程里相关信息不够集中、人工整理成本较高的问题,让日常排查、验证和结果归档更直接。
实现上补充了对应工具或脚本逻辑,补上了对应测试,同时尽量保持现有用法不变,避免影响已有流程。
这一分支已经在沐曦算力环境完成实际验证,相关检查均已通过,现提交合入。