[ROCM-26203] Modify existing tests to work with pytest#4980
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates Python tests under test/py/ to behave correctly under pytest’s test discovery rules by preventing helper functions from being collected as tests.
Changes:
- Rename helper functions from
test_*to_test_*to avoid pytest collection. - Replace the old
test_conv_relu(format)pattern (which pytest interprets as needing a fixture) with two explicit tests for msgpack/json serialization. - Update copyright headers to 2026 in the modified files.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
test/py/test_save_load.py |
Renames the format-taking helper and adds explicit serialization tests (msgpack, json) to avoid pytest fixture/collection issues. |
test/py/test_array.py |
Renames test_shape helper to _test_shape and updates its call sites to prevent unintended pytest collection. |
Comments suppressed due to low confidence (1)
test/py/test_save_load.py:31
- The helper parameter name
formatshadows Python’s built-informat()and makes the call sites harder to read. Consider renaming the parameter to something more specific (e.g.,serialization_format) and forwarding that intomigraphx.save/load.
def _test_conv_relu(format):
p1 = migraphx.parse_onnx("conv_relu_maxpool_test.onnx")
print(p1)
s1 = p1.get_output_shapes()[-1]
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #4980 +/- ##
========================================
Coverage 92.73% 92.73%
========================================
Files 592 594 +2
Lines 31289 31340 +51
========================================
+ Hits 29015 29063 +48
- Misses 2274 2277 +3 🚀 New features to boost your workflow:
|
Regressions detected 🔴 * No develop baseline was found for this PR's branch point; compared against the latest available develop run instead. |
|
TedThemistokleous
left a comment
There was a problem hiding this comment.
LGTM on this one. Good work
| test_input() | ||
| test_output() |
There was a problem hiding this comment.
| if __name__ == "__main__": | |
| test_input() | |
| test_output() |
I maybe wrong, but it seems without the if __name__ == "__main__": guard, the tests will execute twice, first during collection phase and then during execution phase.
Besides double execution, if the tests fail for any reason, pytest will fail at collection phase and it would mask the real-error/failure from the failing test, making it harder to debug.
There was a problem hiding this comment.
That's what I originally thought too, but it seems like when we package the wheel it strips out any function calls. For example, here's what the original (failing) wheel run looked like:
((.venv) ) [root@efac41cc576b ROCM-26203]# pytest --pyargs migraphx_tests -v
============================================================================================================================ test session starts =============================================================================================================================
platform linux -- Python 3.12.13, pytest-9.1.0, pluggy-1.6.0 -- /code/ROCM-26203/.venv/bin/python3.12
cachedir: .pytest_cache
rootdir: /code/ROCM-26203
collected 65 items
.venv/lib/python3.12/site-packages/migraphx_tests/test_array.py::test_shape ERROR [ 1%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_array.py::test_input PASSED [ 3%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_array.py::test_output PASSED [ 4%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_autocast_fp8.py::test_autocast_fp8_1 PASSED [ 6%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_autocast_fp8.py::test_autocast_fp8_2 PASSED [ 7%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_cpu.py::test_conv_relu PASSED [ 9%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_cpu.py::test_add_scalar PASSED [ 10%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_cpu.py::test_module PASSED [ 12%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_debug_symbols.py::test_no_debug_symbols_by_default PASSED [ 13%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_debug_symbols.py::test_add_instruction_with_debug_symbols PASSED [ 15%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_debug_symbols.py::test_add_instruction_empty_debug_symbols PASSED [ 16%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_debug_symbols.py::test_add_instruction_with_mod_args_and_debug_symbols PASSED [ 18%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_debug_symbols.py::test_add_literal_argument_with_debug_symbols PASSED [ 20%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_debug_symbols.py::test_add_parameter_with_debug_symbols PASSED [ 21%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_debug_symbols.py::test_add_return_with_debug_symbols PASSED [ 23%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_debug_symbols.py::test_replace_return_with_debug_symbols PASSED [ 24%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_debug_symbols.py::test_add_macro_with_debug_symbols_tags_all_added PASSED [ 26%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_debug_symbols.py::test_add_macro_without_debug_symbols_is_unchanged PASSED [ 27%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_debug_symbols.py::test_insert_macro_with_debug_symbols PASSED [ 29%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_debug_symbols.py::test_iterate_instructions_debug_symbols PASSED [ 30%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_debug_symbols.py::test_iterate_only_symbolized_instructions PASSED [ 32%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_debug_symbols.py::test_parse_onnx_with_debug_symbols PASSED [ 33%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_debug_symbols.py::test_parse_onnx_without_debug_symbols PASSED [ 35%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_gpu.py::test_conv_relu PASSED [ 36%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_gpu.py::test_sub_uint64 PASSED [ 38%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_gpu.py::test_neg_int64 PASSED [ 40%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_gpu.py::test_nonzero PASSED [ 41%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_gpu.py::test_fp16_imagescaler PASSED [ 43%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_gpu.py::test_if_pl PASSED [ 44%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_gpu.py::test_dyn_batch PASSED [ 46%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_gpu_async.py::test_conv_relu PASSED [ 47%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_gpu_offload.py::test_conv_relu PASSED [ 49%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_instruction.py::test_instruction_shape PASSED [ 50%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_instruction.py::test_instruction_op PASSED [ 52%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_literal.py::test_add_fill PASSED [ 53%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_literal.py::test_add_create PASSED [ 55%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_macro.py::test_macro_name_and_options PASSED [ 56%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_macro.py::test_macro_no_options PASSED [ 58%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_macro.py::test_add_macro_gemm PASSED [ 60%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_macro.py::test_add_macro_gemm_transA PASSED [ 61%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_macro.py::test_add_macro_gemm_with_params PASSED [ 63%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_macro.py::test_add_macro_batchnorm PASSED [ 64%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_macro.py::test_add_macro_batchnorm_with_epsilon PASSED [ 66%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_macro.py::test_add_macro_convolution PASSED [ 67%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_macro.py::test_add_macro_convolution_with_bias PASSED [ 69%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_macro.py::test_add_macro_convolution_with_padding PASSED [ 70%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_macro.py::test_add_macro_einsum_matmul PASSED [ 72%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_macro.py::test_add_macro_einsum_transpose PASSED [ 73%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_macro.py::test_add_macro_einsum_trace PASSED [ 75%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_macro.py::test_insert_macro PASSED [ 76%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_module_construct.py::test_add_op PASSED [ 78%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_module_construct.py::test_if_then_else PASSED [ 80%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_numpy.py::test_add_op PASSED [ 81%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_op.py::test_add_op PASSED [ 83%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_op.py::test_reduce_mean PASSED [ 84%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_save_load.py::test_conv_relu ERROR [ 86%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_save_load.py::test_save_load_buffer PASSED [ 87%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_save_load.py::test_load_save_arg PASSED [ 89%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_shape.py::test_create_shape PASSED [ 90%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_shape.py::test_create_shape_transposed PASSED [ 92%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_shape.py::test_create_shape_broadcast PASSED [ 93%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_shape.py::test_create_shape_type PASSED [ 95%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_shape.py::test_create_dyn_dims PASSED [ 96%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_shape.py::test_create_dyn_shape PASSED [ 98%]
.venv/lib/python3.12/site-packages/migraphx_tests/test_shape.py::test_type_enum PASSED [100%]
test_array only runs test_input() and test_output() once. I can add the main guard if preferred, but then ideally it would be added for all the other files as well to maintain consistency.
Update: Just tested with a manual UFB run to package the wheel and it seems to pass all tests.
There was a problem hiding this comment.
After discussion with Paul, it seems this requires a sync with QA team to ensure they are running tests consistently. I believe my comment would be resolved with that path.
Motivation
Modifies some of our existing tests to work properly with pytest.
Technical Details
By default, pytest picks up any functions in the format of
test_*or*_testand runs them as tests. This PR adds an underscore prefix to any functions that are meant to be helpers and not actual tests.Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot Applicable