Skip to content

Comments

chore(tests): add pytest.main entrypoint to all test files#246

Merged
Hzfengsy merged 2 commits intohw-native-sys:mainfrom
Hzfengsy:chore/test-pytest-main
Feb 23, 2026
Merged

chore(tests): add pytest.main entrypoint to all test files#246
Hzfengsy merged 2 commits intohw-native-sys:mainfrom
Hzfengsy:chore/test-pytest-main

Conversation

@Hzfengsy
Copy link
Member

Summary

  • Add if __name__ == "__main__": pytest.main([__file__, "-v"]) to all 41 test files that were missing it, enabling direct execution via python test_file.py
  • Replace unittest.TestCase / unittest.main() usage with plain pytest in test_pto_codegen_ops.py
  • Replace manual test function calls with pytest.main() in test_type_check_pass.py
  • Normalize import pytest placement to follow import ordering convention (third-party before local)
  • Update github-pr skill to detect branches with zero commits ahead of upstream that need a new branch before creating a PR

Testing

  • All 1520 tests pass (0 failures)
  • Code review completed
  • Pre-commit hooks pass (ruff, pyright, markdownlint)

Copilot AI review requested due to automatic review settings February 22, 2026 13:00
@coderabbitai
Copy link

coderabbitai bot commented Feb 22, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
Documentation
.claude/skills/github-pr/SKILL.md
Restructures "Prerequisites" section into "Workflow Steps" with 6 detailed steps covering branch preparation, PR existence checks, rebasing, and pushing. Adds explicit decision logic, concrete commands (branch creation, fetch, rebase, push with --force-with-lease), and troubleshooting guidance for gh CLI usage.
System Tests - Codegen & Runtime
tests/st/codegen/test_add_mul_orch_cce_codegen.py, tests/st/harness/core/test_runner.py, tests/st/runtime/test_dag.py, tests/st/runtime/test_elementwise.py, tests/st/runtime/test_matmul.py
Adds pytest import and if __name__ == "__main__": pytest.main([__file__, "-v"]) entry point to enable direct script execution.
Unit Tests - Backend
tests/ut/backend/test_backend.py, tests/ut/backend/test_backend_910b.py
Adds pytest import and main entry point for standalone script execution.
Unit Tests - Codegen
tests/ut/codegen/test_cce_codegen.py, tests/ut/codegen/test_orchestration_codegen.py, tests/ut/codegen/test_pto_codegen.py, tests/ut/codegen/test_type_converter.py
Adds pytest import and main guard for direct execution (4 files); test_pto_codegen_ops.py converted from unittest.TestCase to plain pytest-style class with backend reset and setup.
Unit Tests - IR (High-Level, Operators, Statements)
tests/ut/ir/high_level/test_function.py, tests/ut/ir/high_level/test_program.py, tests/ut/ir/operators/test_operator_spans.py, tests/ut/ir/statements/test_eval_stmt.py, tests/ut/ir/statements/test_scope_stmt.py, tests/ut/ir/statements/test_seq_stmts.py, tests/ut/ir/statements/test_while_stmt.py
Adds pytest import and main entry point to enable standalone test execution across 7 test modules.
Unit Tests - IR Transforms
tests/ut/ir/transforms/test_basic_memory_reuse.py, tests/ut/ir/transforms/test_convert_tensor_to_block_ops.py, tests/ut/ir/transforms/test_flatten_call_expr_pass.py, tests/ut/ir/transforms/test_flatten_single_stmt_pass.py, tests/ut/ir/transforms/test_hash.py, tests/ut/ir/transforms/test_init_memref.py, tests/ut/ir/transforms/test_insert_sync.py, tests/ut/ir/transforms/test_ir_property.py, tests/ut/ir/transforms/test_normalize_stmt_structure_pass.py, tests/ut/ir/transforms/test_outline_incore_scopes.py, tests/ut/ir/transforms/test_parent_stmt_analysis.py, tests/ut/ir/transforms/test_pass_manager.py, tests/ut/ir/transforms/test_pass_pipeline.py, tests/ut/ir/transforms/test_type_check_pass.py, tests/ut/ir/transforms/test_verify_no_nested_call_pass.py
Adds pytest import and/or main entry point across 15 test modules; adjusts import placement in some files to module-level; test_type_check_pass.py replaces manual invocation with pytest.main().
Unit Tests - Language Parser
tests/ut/language/parser/test_error_cases.py, tests/ut/language/parser/test_expr_evaluator.py, tests/ut/language/parser/test_printer_integration.py, tests/ut/language/parser/test_scope_manager.py, tests/ut/language/parser/test_scope_parsing.py, tests/ut/language/parser/test_span_tracker.py, tests/ut/language/parser/test_text_parser.py, tests/ut/language/parser/test_tuple_syntax.py, tests/ut/language/parser/test_type_resolver.py
Adds pytest import and main guard for direct execution across 9 test modules in the parser layer.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~18 minutes

Possibly related PRs

Poem

🐰 With pytest's gentle guard, the tests now run
No runner needed—straight from script they come!
From workflow steps refined, workflows shine bright,
Each test file ready for a solo flight.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: adding pytest.main entrypoints to test files, which is the primary focus of this PR.
Description check ✅ Passed The description is comprehensive and clearly related to the changeset, providing specific details about what was changed, why, and testing confirmation.
Docstring Coverage ✅ Passed Docstring coverage is 95.24% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 pytest.main entrypoints to numerous test files, developers can now execute individual tests directly, fostering faster iteration and debugging. Additionally, the PR refines the github-pr skill's guidance on branch management, ensuring a more robust and intuitive process for preparing pull requests.

Highlights

  • Test Execution Improvement: Enabled direct execution of 41 Python test files by adding a pytest.main entrypoint, allowing individual tests to be run via python test_file.py.
  • Testing Framework Migration: Migrated test_pto_codegen_ops.py from unittest.TestCase to plain pytest functions, streamlining its testing approach.
  • Test Call Normalization: Replaced manual test function calls with pytest.main() in test_type_check_pass.py, standardizing test execution.
  • Import Ordering Standardization: Standardized import pytest placement across test files to adhere to conventional import ordering (third-party before local).
  • GitHub PR Workflow Enhancement: Enhanced the github-pr skill documentation to clarify the logic for creating new branches, especially when a branch has zero commits ahead of upstream.
Changelog
  • .claude/skills/github-pr/SKILL.md
    • Updated the "Workflow Steps" section to include "Prepare branch and commit".
    • Added detailed "Step 1: Prepare Branch and Commit" section with decision logic for new branch creation.
    • Renumbered subsequent workflow steps (Fetch Upstream, Rebase, Push, Create PR).
    • Revised the "Checklist" to reflect the new branch preparation steps.
  • tests/st/codegen/test_add_mul_orch_cce_codegen.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/st/harness/core/test_runner.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/st/runtime/test_dag.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/st/runtime/test_elementwise.py
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/st/runtime/test_matmul.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/backend/test_backend.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/backend/test_backend_910b.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/codegen/test_cce_codegen.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/codegen/test_orchestration_codegen.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/codegen/test_pto_codegen.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/codegen/test_pto_codegen_ops.py
    • Removed unittest import.
    • Added import pytest.
    • Updated Test910BBlockOpsCodegen class to not inherit from unittest.TestCase.
    • Replaced unittest.main() with pytest.main([__file__, "-v"]).
  • tests/ut/codegen/test_type_converter.py
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/high_level/test_function.py
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/high_level/test_program.py
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/operators/test_operator_spans.py
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/statements/test_eval_stmt.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/statements/test_scope_stmt.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/statements/test_seq_stmts.py
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/statements/test_while_stmt.py
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/transforms/test_basic_memory_reuse.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/transforms/test_convert_tensor_to_block_ops.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/transforms/test_flatten_call_expr_pass.py
    • Added import pytest.
    • Removed redundant import pytest from the main execution block.
  • tests/ut/ir/transforms/test_flatten_single_stmt_pass.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/transforms/test_hash.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/transforms/test_init_memref.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/transforms/test_insert_sync.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/transforms/test_ir_property.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/transforms/test_normalize_stmt_structure_pass.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/transforms/test_outline_incore_scopes.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/transforms/test_parent_stmt_analysis.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/transforms/test_pass_manager.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/transforms/test_pass_pipeline.py
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/ir/transforms/test_type_check_pass.py
    • Added import pytest.
    • Replaced manual test function calls with a pytest.main entrypoint.
  • tests/ut/ir/transforms/test_verify_no_nested_call_pass.py
    • Added import pytest.
    • Removed redundant import pytest from the main execution block.
  • tests/ut/language/parser/test_error_cases.py
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/language/parser/test_expr_evaluator.py
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/language/parser/test_printer_integration.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/language/parser/test_scope_manager.py
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/language/parser/test_scope_parsing.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/language/parser/test_span_tracker.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/language/parser/test_text_parser.py
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/language/parser/test_tuple_syntax.py
    • Added import pytest.
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
  • tests/ut/language/parser/test_type_resolver.py
    • Appended if __name__ == "__main__": pytest.main([__file__, "-v"]) block.
Activity
  • All 1520 tests passed with 0 failures.
  • Code review was completed.
  • Pre-commit hooks (ruff, pyright, markdownlint) passed.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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.

pytest should be listed before pypto.* 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 pytest on line 17 appears after the local import pypto and import 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 pytest on line 13 appears after the local import pypto.language as pl on 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 pytest on line 24 appears after the local import 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).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 normalize import pytest placement where needed).
  • Convert tests/ut/codegen/test_pto_codegen_ops.py from unittest.TestCase/unittest.main() to pure pytest style.
  • Update .claude/skills/github-pr/SKILL.md to 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.

Hzfengsy added a commit to Hzfengsy/pypto that referenced this pull request Feb 22, 2026
- 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
@Hzfengsy Hzfengsy force-pushed the chore/test-pytest-main branch from 0d8cbaa to 4bc9118 Compare February 23, 2026 04:25
@Hzfengsy Hzfengsy merged commit 01b23c8 into hw-native-sys:main Feb 23, 2026
5 checks passed
@Hzfengsy Hzfengsy deleted the chore/test-pytest-main branch February 23, 2026 04:27
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