Skip to content

[Test] Restore shadowed duplicate test functions in relax/runtime tests - #20326

Open
Anai-Guo wants to merge 1 commit into
apache:mainfrom
Anai-Guo:test/restore-shadowed-duplicate-tests
Open

Anai-Guo wants to merge 1 commit into
apache:mainfrom
Anai-Guo:test/restore-shadowed-duplicate-tests

Conversation

@Anai-Guo

Copy link
Copy Markdown
Contributor

Several relax/runtime test modules define the same test function name twice. The second def rebinds the module-level name, so pytest only collects the later one and the earlier test silently never runs. File-level # ruff: noqa: F811 headers were hiding the lint signal (ruff check --select F811 --ignore-noqa shows them).

File Duplicate Fix
relax/test_expr.py test_match_cast (two different tests) Rename the second to test_match_cast_json_roundtrip. The restored first test still used the removed MatchCast.pattern field → switched to b.ty.shape[i].same_as(m).
relax/test_ast_printer.py test_shape_expr (symbolic vars vs. constants) Rename the first to test_shape_expr_symbolic. ShapeExpr now requires int64 values, so the vars are int64 and the expected printout is Expr(value=`m`).
runtime/test_runtime_nd_array.py test_1d_view_of_first_half_of_1d_arr The second one uses relative_byte_offset=512 * 4 → rename to test_1d_view_of_second_half_of_1d_arr (mirrors the existing 2d pair).
relax/test_transform_gradient_checkpoint.py test_checkpoint_dag The second copy — the one pytest was collecting — is truncated: it builds the function but has no Expected module and no assert_structural_equal. Removed it so the full test runs.
relax/test_analysis.py test_reshape_pattern_reject_reduction Byte-identical second copy removed.
relax/test_analysis_well_formed.py test_incomplete_ty_must_be_consistent Byte-identical second copy removed.

F811 is dropped from the file-level noqa headers that no longer need it (otherwise RUF100 fires).

Left alone: test_op_gradient_numeric.py::test_reshape has the same issue, but it is LLVM-gated and I could not run it locally, so it is not included here.

Testing

CPU build of current main (ccd98e9, USE_LLVM OFF), pytest per file:

File before after
relax/test_expr.py 31 passed 32 passed
relax/test_ast_printer.py 24 passed 25 passed
runtime/test_runtime_nd_array.py 14 passed 15 passed
relax/test_transform_gradient_checkpoint.py 11 passed 11 passed (test_checkpoint_dag now includes the structural-equality check)
relax/test_analysis.py 37 passed 37 passed
relax/test_analysis_well_formed.py 57 passed, 2 xfailed 57 passed, 2 xfailed

Without the two small updates, the restored test_match_cast fails with AttributeError: 'MatchCast' object has no attribute 'pattern' and test_shape_expr_symbolic fails with the value in ShapeType can only have dtype of int64, i.e. both had drifted while hidden.

ruff check / ruff format --check (v0.12.3, repo config) pass on all six files.

🤖 Generated with Claude Code

Several test modules define the same test function name twice. The
second definition rebinds the module-level name, so pytest only
collects the later one and the earlier test silently never runs.
File-level `# ruff: noqa: F811` headers were hiding the lint signal.

- test_expr.py: rename the second test_match_cast to
  test_match_cast_json_roundtrip; update the restored first test from
  the removed MatchCast.pattern field to MatchCast.ty.shape.
- test_ast_printer.py: rename the first test_shape_expr to
  test_shape_expr_symbolic; ShapeExpr now requires int64 symbolic vars,
  so update the vars and expected printout accordingly.
- test_runtime_nd_array.py: the second test_1d_view_of_first_half_of_1d_arr
  views the second half via relative_byte_offset; rename it to
  test_1d_view_of_second_half_of_1d_arr (matching the 2d variant).
- test_transform_gradient_checkpoint.py: the second test_checkpoint_dag
  is a truncated copy without the Expected module or the
  assert_structural_equal check, and it was the one being collected.
  Remove it so the full test runs.
- test_analysis.py / test_analysis_well_formed.py: remove byte-identical
  second copies of test_reshape_pattern_reject_reduction and
  test_incomplete_ty_must_be_consistent.

Drop F811 from the file-level noqa headers that no longer need it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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