[AIMIGRAPHX-1151] Add pytest bridge for unit tests#5006
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a Python/pytest “bridge” to run MIGraphX’s existing CTest-registered unit test executables under pytest, and installs that bridge alongside the installed C++ tests so it can be used from packaged test artifacts (e.g., the tests component / migraphx_tests wheel).
Changes:
- Add
test/test_pytest_bridge.py, which discovers tests viactest --show-only=json-v1(or by scanningbin/) and runs each test executable as a pytest parameterized case. - Install the bridge script via
rocm_install_test(...)so it is available next to installed test binaries.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
test/test_pytest_bridge.py |
Adds pytest-based discovery/execution wrapper around existing CTest tests. |
test/CMakeLists.txt |
Installs the pytest bridge script alongside installed C++ tests. |
| def _make_test(name, command, env=None, fail_regexes=None, skip=None): | ||
| return { | ||
| "name": name, | ||
| "command": command, | ||
| "env": env or {}, | ||
| "fail_regexes": fail_regexes or ["FAILED"], | ||
| "skip": skip, | ||
| } |
| env_extra = {} | ||
| fail_regexes = None | ||
| needs_fixture = False | ||
| for prop in entry.get("properties", []): | ||
| name = prop.get("name") | ||
| if name == "ENVIRONMENT": | ||
| for item in prop.get("value", []): | ||
| key, _, value = item.partition("=") | ||
| env_extra[key] = value | ||
| elif name == "FAIL_REGULAR_EXPRESSION" and prop.get("value"): | ||
| value = prop["value"] | ||
| fail_regexes = value if isinstance(value, list) else [value] | ||
| elif name in _FIXTURE_PROPS and prop.get("value"): | ||
| needs_fixture = True | ||
| tests.append(_make_test( | ||
| entry["name"], command, env=env_extra, fail_regexes=fail_regexes, | ||
| skip="requires ctest fixtures; run via ctest" if needs_fixture else None)) |
| result = subprocess.run( | ||
| spec["command"], | ||
| cwd=_TEST_DIR, | ||
| env=_make_env(spec["env"]), | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.STDOUT, | ||
| text=True, | ||
| ) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #5006 +/- ##
========================================
Coverage 92.71% 92.71%
========================================
Files 594 594
Lines 31465 31478 +13
========================================
+ Hits 29170 29183 +13
Misses 2295 2295 🚀 New features to boost your workflow:
|
Regressions detected 🔴 |
|
|
pytest should run the tests with CTest. It looks like its trying to extract the command which seems complicated due to fixtures. Instead it should find each test and skip fixtures. Then run the test with |
|
Since pytest runs serially we dont have to worry about And even simpler pytest bridge is to add just one test and call |
Implemented this which simplifies the bridge by quite a lot. Only downside is that when run through pytest you only see 1 test and no progress updates until something either fails or it all succeeds. |
|
You can use the |
|
Requires ROCm/rocm-cmake#289 to be merged first. |
Motivation
Adds a pytest bridge to support running of CTest unit tests with pytest.
Technical Details
A specific test dir can be manually passed in with
MIGRAPHX_TEST_DIR. Mostly generated with Claude; tested with CI build.Example of output:
Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot Applicable