chore(tests): add pytest.main entrypoint to all test files#246
chore(tests): add pytest.main entrypoint to all test files#246Hzfengsy merged 2 commits intohw-native-sys:mainfrom
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR restructures the GitHub PR workflow documentation into detailed workflow steps with concrete commands and decision logic, and adds pytest entry point guards to 45+ test files enabling direct script execution without external test runners. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~18 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
Summary of ChangesHello @Hzfengsy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the developer experience for running tests and streamlines the GitHub PR creation workflow. By adding Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request is a great improvement for developer experience, adding a pytest.main entrypoint to all test files, which allows them to be run directly. The standardization to pytest and normalization of imports are also good for code consistency. The update to the github-pr skill documentation clarifies the branching and commit workflow, making it easier to follow. I have one minor suggestion to correct the numbering in a list in the documentation.
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (5)
tests/ut/ir/statements/test_scope_stmt.py (1)
12-14: Reorder imports to keep third‑party before local modules.
pytestshould be listed beforepypto.*to match the stated import ordering convention.🔧 Suggested reorder
-import pypto.language as pl import pytest +import pypto.language as pl from pypto import DataType, ir🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/ut/ir/statements/test_scope_stmt.py` around lines 12 - 14, Reorder the import statements so third‑party modules come before local packages: place "import pytest" above the "import pypto.language as pl" and "from pypto import DataType, ir" lines; update the import block that currently contains "import pypto.language as pl", "import pytest", and "from pypto import DataType, ir" to follow the convention (pytest first, then pypto.*)..claude/skills/github-pr/SKILL.md (1)
8-16: Fix step-number mismatch between the summary and section headers.Workflow Steps list “Resolve conflicts” as Step 5, but the detailed sections label Step 5 as “Push” and Step 6 as “Create PR”. This makes the guide internally inconsistent. Suggest aligning the numbered section headers with the list (or updating the list).
Also applies to: 87-100
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.claude/skills/github-pr/SKILL.md around lines 8 - 16, The numbered "Workflow Steps" list and the detailed section headers are out of sync: the list shows "Resolve conflicts" as Step 5 but the detailed headers currently label Step 5 as "Push" and Step 6 as "Create PR"; update the section header numbers (or the numbered list) so the detailed step titles match the summary order (e.g., ensure the header containing "Resolve conflicts" is labeled Step 5, "Push to fork with --force-with-lease" is Step 6, and "Create PR using gh CLI" is Step 7), and mirror the same renumbering for the repeated instance later in the file (the other block around the 87-100 region) so both places are consistent.tests/ut/language/parser/test_text_parser.py (1)
15-18: Import ordering inconsistency.The
import pyteston line 17 appears after the localimport pyptoandimport pypto.language as pl. Third-party imports should precede local imports per PEP 8 conventions and the PR objectives.🔧 Suggested fix
import os import tempfile +import pytest + import pypto import pypto.language as pl -import pytest from pypto import ir🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/ut/language/parser/test_text_parser.py` around lines 15 - 18, Reorder the imports in the test module so third-party imports come before local package imports: move "import pytest" above the local "import pypto" and "import pypto.language as pl" (keeping "from pypto import ir" with other pypto imports); update the import block that currently references pypto, pl, pytest, and ir so it follows PEP 8 ordering (standard libs, third-party like pytest, then local package imports).tests/ut/codegen/test_cce_codegen.py (1)
12-14: Import ordering inconsistency.The
import pyteston line 13 appears after the localimport pypto.language as plon line 12, which violates the PEP 8 convention (third-party imports should precede local imports). The PR objectives state this should be normalized.🔧 Suggested fix
-import pypto.language as pl import pytest + +import pypto.language as pl from pypto import DataType, backend, codegen, ir🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/ut/codegen/test_cce_codegen.py` around lines 12 - 14, Reorder the imports so third-party packages come before local project imports: move "import pytest" to appear before "import pypto.language as pl" and ensure the block groups standard library, third-party (pytest) and then local "pypto" imports (DataType, backend, codegen, ir); update the import order in the module (tests/ut/codegen/test_cce_codegen.py) accordingly or run the project's import-sorting tool (isort) to normalize the file.tests/ut/ir/transforms/test_verify_no_nested_call_pass.py (1)
23-25: Import ordering inconsistency.The
import pyteston line 24 appears after the localimport pypto.language as pl. Third-party imports should precede local imports per PEP 8 conventions. While moving the import to module-level is correct, the placement should be adjusted.🔧 Suggested fix
+import pytest + import pypto.language as pl -import pytest from pypto import passes🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/ut/ir/transforms/test_verify_no_nested_call_pass.py` around lines 23 - 25, The test module has imports out of PEP8 order: the third-party import pytest should come before local package imports; update the import order so that "import pytest" appears above "import pypto.language as pl" and "from pypto import passes" (keep all imports at module level and preserve existing aliases like pl).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.claude/skills/github-pr/SKILL.md:
- Around line 22-27: The script uses git rev-list HEAD --not upstream/main
--count which fails if the upstream remote is missing; modify the flow to detect
whether the remote 'upstream' exists (e.g., with git remote or git ls-remote)
and set a variable (e.g., REMOTE=$(git remote | grep -q upstream && echo
upstream || echo origin)) or similar, then replace the hardcoded upstream/main
in the git rev-list call with the chosen remote branch (e.g., ${REMOTE}/main);
update references around BRANCH_NAME and the rev-list invocation so the count
falls back to origin/main when upstream is absent.
In `@tests/st/runtime/test_matmul.py`:
- Around line 80-81: The test script currently calls pytest.main([...]) without
propagating its exit code; update the __main__ guard to capture pytest.main(...)
return value and propagate it via SystemExit (or sys.exit) so the process exits
with pytest's status; locate the if __name__ == "__main__": block and change the
call that invokes pytest.main to raise SystemExit(pytest.main([__file__, "-v"]))
(or pass the return value to sys.exit) to ensure correct exit codes.
In `@tests/ut/ir/statements/test_eval_stmt.py`:
- Around line 84-85: The module-level runner currently calls
pytest.main([__file__, "-v"]) but does not propagate its return code; change the
bottom block so it captures the return value from pytest.main(...) and then
raise SystemExit(return_code) (or call raise SystemExit(ret)) when __name__ ==
"__main__" to forward pytest's exit status; locate the pytest.main invocation in
the module-level guarded block and replace the direct call with capturing the
result and raising SystemExit with that result.
In `@tests/ut/ir/statements/test_scope_stmt.py`:
- Around line 66-67: The __main__ guard calls pytest.main([__file__, "-v"]) but
discards its return value; change the block so you capture the return code from
pytest.main(...) and pass it to sys.exit(...) to propagate failures, and ensure
sys is imported if not already; look for the "__main__" guard and the
pytest.main call in test_scope_stmt.py to implement this change.
In `@tests/ut/ir/transforms/test_convert_tensor_to_block_ops.py`:
- Around line 421-422: The script's "__main__" block calls
pytest.main([__file__, "-v"]) but ignores its returned exit code; modify the
block so the returned code is propagated (e.g., call
sys.exit(pytest.main([__file__, "-v"])) or raise SystemExit(return_code)) and
add the required import for sys; update the "__main__" section that invokes
pytest.main to capture its return value and exit with it so CI sees test
failures.
---
Duplicate comments:
In `@tests/ut/codegen/test_orchestration_codegen.py`:
- Around line 893-894: The test runner invocation in the if __name__ ==
"__main__": block currently calls pytest.main([__file__, "-v"]) directly so
non-zero exit codes aren't propagated; change that invocation to raise
SystemExit(pytest.main([__file__, "-v"])) so the process exits with pytest's
return code—update the main guard where pytest.main is called to wrap it in
SystemExit.
In `@tests/ut/codegen/test_pto_codegen.py`:
- Around line 373-374: The test runner block currently calls
pytest.main([__file__, "-v"]) directly in the if __name__ == "__main__":
section; change it to propagate pytest's exit code by raising SystemExit with
the return code (i.e., replace the direct pytest.main(...) call with raise
SystemExit(pytest.main([__file__, "-v"]))) so non-zero failures produce a
non-zero process exit; update the call in the main guard where pytest.main is
invoked.
In `@tests/ut/ir/high_level/test_function.py`:
- Around line 436-437: The current test runner under the main guard calls
pytest.main([__file__, "-v"]) directly which doesn't propagate non-zero exit
codes; change the block that checks if __name__ == "__main__" to raise
SystemExit(pytest.main([__file__, "-v"])) (i.e., replace the bare pytest.main
call with raise SystemExit(...)) so failures produce a non-zero process exit
status.
In `@tests/ut/ir/transforms/test_flatten_single_stmt_pass.py`:
- Around line 359-360: Replace the current test script's top-level runner that
calls pytest.main([__file__, "-v"]) inside the if __name__ == "__main__" block
so that the process exits with pytest's return code; specifically, wrap the
pytest.main(...) call in a SystemExit (e.g., raise
SystemExit(pytest.main([...]))), updating the __main__ block where pytest.main
is invoked to propagate non‑zero exit codes back to the caller.
In `@tests/ut/language/parser/test_error_cases.py`:
- Around line 277-278: The current test runner block calls
pytest.main([__file__, "-v"]) directly which can swallow non-zero exit codes;
wrap the call in a SystemExit to propagate failures by replacing the if __name__
== "__main__": clause so it raises SystemExit(pytest.main([__file__, "-v"]))
instead of calling pytest.main(...) directly, referencing the pytest.main
invocation in this file to locate and update the block.
In `@tests/ut/language/parser/test_scope_parsing.py`:
- Around line 111-112: The top-level test runner under the "__name__ ==
'__main__'" guard calls pytest.main(...) directly, which loses non-zero exit
codes; change that call to propagate the exit code by raising or calling
SystemExit with pytest.main(...) (e.g., replace pytest.main([__file__, "-v"])
with raise SystemExit(pytest.main([__file__, "-v"]))) so pytest.main's exit
status is preserved.
In `@tests/ut/language/parser/test_tuple_syntax.py`:
- Around line 133-134: Replace the direct call to pytest.main(...) inside the if
__name__ == "__main__": guard so non-zero test failures propagate as a real exit
code; specifically wrap the call using the SystemExit pattern (e.g., raise
SystemExit(pytest.main([__file__, "-v"]))) instead of calling pytest.main(...)
directly, targeting the block that currently invokes pytest.main in
tests/ut/language/parser/test_tuple_syntax.py.
---
Nitpick comments:
In @.claude/skills/github-pr/SKILL.md:
- Around line 8-16: The numbered "Workflow Steps" list and the detailed section
headers are out of sync: the list shows "Resolve conflicts" as Step 5 but the
detailed headers currently label Step 5 as "Push" and Step 6 as "Create PR";
update the section header numbers (or the numbered list) so the detailed step
titles match the summary order (e.g., ensure the header containing "Resolve
conflicts" is labeled Step 5, "Push to fork with --force-with-lease" is Step 6,
and "Create PR using gh CLI" is Step 7), and mirror the same renumbering for the
repeated instance later in the file (the other block around the 87-100 region)
so both places are consistent.
In `@tests/ut/codegen/test_cce_codegen.py`:
- Around line 12-14: Reorder the imports so third-party packages come before
local project imports: move "import pytest" to appear before "import
pypto.language as pl" and ensure the block groups standard library, third-party
(pytest) and then local "pypto" imports (DataType, backend, codegen, ir); update
the import order in the module (tests/ut/codegen/test_cce_codegen.py)
accordingly or run the project's import-sorting tool (isort) to normalize the
file.
In `@tests/ut/ir/statements/test_scope_stmt.py`:
- Around line 12-14: Reorder the import statements so third‑party modules come
before local packages: place "import pytest" above the "import pypto.language as
pl" and "from pypto import DataType, ir" lines; update the import block that
currently contains "import pypto.language as pl", "import pytest", and "from
pypto import DataType, ir" to follow the convention (pytest first, then
pypto.*).
In `@tests/ut/ir/transforms/test_verify_no_nested_call_pass.py`:
- Around line 23-25: The test module has imports out of PEP8 order: the
third-party import pytest should come before local package imports; update the
import order so that "import pytest" appears above "import pypto.language as pl"
and "from pypto import passes" (keep all imports at module level and preserve
existing aliases like pl).
In `@tests/ut/language/parser/test_text_parser.py`:
- Around line 15-18: Reorder the imports in the test module so third-party
imports come before local package imports: move "import pytest" above the local
"import pypto" and "import pypto.language as pl" (keeping "from pypto import ir"
with other pypto imports); update the import block that currently references
pypto, pl, pytest, and ir so it follows PEP 8 ordering (standard libs,
third-party like pytest, then local package imports).
There was a problem hiding this comment.
Pull request overview
Adds a consistent pytest.main() __main__ entrypoint across the test suite so individual test modules can be executed directly with python path/to/test_file.py, and updates internal workflow documentation for creating PRs.
Changes:
- Add
if __name__ == "__main__": pytest.main([__file__, "-v"])to many test modules (and normalizeimport pytestplacement where needed). - Convert
tests/ut/codegen/test_pto_codegen_ops.pyfromunittest.TestCase/unittest.main()to pure pytest style. - Update
.claude/skills/github-pr/SKILL.mdto better handle “feature branch with 0 commits ahead of upstream” scenarios.
Reviewed changes
Copilot reviewed 44 out of 44 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/ut/language/parser/test_type_resolver.py | Add pytest __main__ entrypoint. |
| tests/ut/language/parser/test_tuple_syntax.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/language/parser/test_text_parser.py | Add pytest __main__ entrypoint. |
| tests/ut/language/parser/test_span_tracker.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/language/parser/test_scope_parsing.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/language/parser/test_scope_manager.py | Add pytest __main__ entrypoint. |
| tests/ut/language/parser/test_printer_integration.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/language/parser/test_expr_evaluator.py | Add pytest __main__ entrypoint. |
| tests/ut/language/parser/test_error_cases.py | Add pytest __main__ entrypoint. |
| tests/ut/ir/transforms/test_verify_no_nested_call_pass.py | Move import pytest to top-level; keep pytest __main__ entrypoint. |
| tests/ut/ir/transforms/test_type_check_pass.py | Replace manual test invocation with pytest.main() entrypoint. |
| tests/ut/ir/transforms/test_pass_pipeline.py | Add pytest __main__ entrypoint. |
| tests/ut/ir/transforms/test_pass_manager.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/ir/transforms/test_parent_stmt_analysis.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/ir/transforms/test_outline_incore_scopes.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/ir/transforms/test_normalize_stmt_structure_pass.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/ir/transforms/test_ir_property.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/ir/transforms/test_insert_sync.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/ir/transforms/test_init_memref.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/ir/transforms/test_hash.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/ir/transforms/test_flatten_single_stmt_pass.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/ir/transforms/test_flatten_call_expr_pass.py | Move import pytest to top-level; keep pytest __main__ entrypoint. |
| tests/ut/ir/transforms/test_convert_tensor_to_block_ops.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/ir/transforms/test_basic_memory_reuse.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/ir/statements/test_while_stmt.py | Add pytest __main__ entrypoint. |
| tests/ut/ir/statements/test_seq_stmts.py | Add pytest __main__ entrypoint. |
| tests/ut/ir/statements/test_scope_stmt.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/ir/statements/test_eval_stmt.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/ir/operators/test_operator_spans.py | Add pytest __main__ entrypoint. |
| tests/ut/ir/high_level/test_program.py | Add pytest __main__ entrypoint. |
| tests/ut/ir/high_level/test_function.py | Add pytest __main__ entrypoint. |
| tests/ut/codegen/test_type_converter.py | Add pytest __main__ entrypoint. |
| tests/ut/codegen/test_pto_codegen_ops.py | Remove unittest usage; convert to pytest style; add pytest __main__ entrypoint. |
| tests/ut/codegen/test_pto_codegen.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/codegen/test_orchestration_codegen.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/codegen/test_cce_codegen.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/backend/test_backend_910b.py | Add import pytest + pytest __main__ entrypoint. |
| tests/ut/backend/test_backend.py | Add import pytest + pytest __main__ entrypoint. |
| tests/st/runtime/test_matmul.py | Add import pytest + pytest __main__ entrypoint. |
| tests/st/runtime/test_elementwise.py | Add pytest __main__ entrypoint. |
| tests/st/runtime/test_dag.py | Add import pytest + pytest __main__ entrypoint. |
| tests/st/harness/core/test_runner.py | Add import pytest + pytest __main__ entrypoint. |
| tests/st/codegen/test_add_mul_orch_cce_codegen.py | Add import pytest + pytest __main__ entrypoint. |
| .claude/skills/github-pr/SKILL.md | Expand PR workflow steps and add branch-prep decision logic. |
- Add upstream/origin fallback for git rev-list base ref
Ensure every test file can be run directly via `python test_file.py`. Add `if __name__ == "__main__": pytest.main([__file__, "-v"])` to all test files that were missing it. Replace unittest.TestCase usage with plain pytest classes. Normalize import ordering to place pytest before local imports. Also update github-pr skill to detect zero-commits-ahead branches that need a new branch before creating a PR.
- Add upstream/origin fallback for git rev-list base ref
0d8cbaa to
4bc9118
Compare
Summary
if __name__ == "__main__": pytest.main([__file__, "-v"])to all 41 test files that were missing it, enabling direct execution viapython test_file.pyunittest.TestCase/unittest.main()usage with plain pytest intest_pto_codegen_ops.pypytest.main()intest_type_check_pass.pyimport pytestplacement to follow import ordering convention (third-party before local)github-prskill to detect branches with zero commits ahead of upstream that need a new branch before creating a PRTesting