Skip to content

fix(test): fail the run when a check fails, and fix the NVMLError contract - #19

Merged
yeahdongcn merged 1 commit into
mainfrom
fix/make-test
Dec 4, 2026
Merged

yeahdongcn merged 1 commit into
mainfrom
fix/make-test

Conversation

@yeahdongcn

@yeahdongcn yeahdongcn commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Three things were wrong with the test surface, all of them visible only when
the suite is read closely:

1. make test collected functions that are not tests. The two helpers
(test_error, test_api) and the six device probes in test_sglang_compat.py
take their arguments from main(), so pytest stopped with
fixture 'devices' not found: 24 passed, 8 errors.

2. The scripts never failed. test_error/test_api counted nothing and
their 77 return values were dropped, and main() returned 1 only when the
library failed to initialize. A broken API printed a line and the script exited
0, so the CI steps could not see it. Measured on an S5000 before this change:
test_pymtml.py printed 120 [MTMLError: Not Supported] lines and exited 0.

3. The pynvml exception contract did not hold. NVMLError was a subclass
of MTMLError, while _mtmlCheckReturn raises MTMLError, so
except pynvml.NVMLError — the pattern test_pynvml.py itself uses — caught
nothing and fell through to except Exception. The wrong branch is visible in
the output: nvmlDeviceGetMaxClockInfo (GRAPHICS): [Error: Not Supported].
MANUAL.md already documents NVMLError = MTMLError; the code now matches, which
also makes every NVMLError_* a subclass of NVMLError as pynvml guarantees.

What changed

  • helpers marked __test__ = False (pytest's documented opt-out) — names and
    call sites unchanged;
  • test_error / test_api count passed / skipped / failed, the run prints a
    summary, and main() returns 1 when anything failed;
  • Not Supported counts as skipped, not failed: those APIs are absent on
    this hardware (ECC, MPC/virtualization, memory vendor…), and turning a
    platform answer into a red build would train everyone to ignore it;
  • NVMLError = MTMLError.

Verification (MTT S5000, vllm:v0.32.0-ph1-5.2.0-torch2.13.0)

make test                    24 passed in 0.09s
python test_pymtml.py        646 passed, 120 skipped (not supported), 0 failed
python test_pynvml.py         57 passed,   2 skipped (not supported), 0 failed
python test_sglang_compat.py exit 0

nvmlDeviceGetMaxClockInfo (GRAPHICS): [NVMLError: Not Supported] (not supported)
nvmlDeviceGetMaxClockInfo (MEM): 2500

The gate fires: injecting a RuntimeError into one API makes main() return 1.

@yeahdongcn yeahdongcn left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Merge verdict: no blocking findings — ready to merge.

Reviewed c026ef4 (+25/−0, test-only). The eight suppressed names are exactly the eight collection errors; the remaining 24 collected items match the author's 24 passed. Mechanism checked in the pytest 9.0.1 source; make test was not re-run here (no MTML hardware).

CI: Unit-test-job is pending in both runs — not in yet, nothing failed, so merge waits on the runner.

Findings: 0 blocking · 2 nit

nit location problem fix
nit .github/workflows/main.yml:15 make test runs in no CI job and skips both suite classes run the three scripts from make test; add CI --collect-only
nit test_pymtml.py:373 same three-line rationale copied into three files; one clause narrates the past collapse to # Helper for main(); not a pytest case.
Diff map · verification · what I could not verify

Diff map (one commit, three files, additions only)

  • test_pymtml.py:373-376 — module-level test_error.__test__ = False; helper is def test_error(name, func) at :25.
  • test_pynvml.py:397-399 — module-level test_api.__test__ = False; helper is def test_api(name, func) at :27.
  • test_sglang_compat.py:271-282 — loop over the six probes that take required parameters: :61, :117, :152, :177, :200, :217.

Verified statically

  • __test__ = False suppresses collection silently: _pytest/python.py:243 reads elif getattr(obj, "__test__", True): and returns None, so no item, no fixture lookup, no PytestCollectionWarning.
  • Every function pytest would collect with a required argument is covered. Outside the six probes, the only module-level test_* names are test_error (marked) in test_pymtml.py and test_api (marked) in test_pynvml.py; test_init_shutdown_cycle and test_p2p_constants take no arguments.
  • Item arithmetic: 10 (test_abi_layout.py) + 7 (test_library_lifecycle.py) + 3 (test_library_loading.py) + 2 (test_mtlink_visibility.py) + 1 + 1 = 24. No parametrize and no import pytest in any of the seven files, so 24 is exact, and 6 + 1 + 1 = the 8 reported errors.
  • MtmlTestSuite / PynvmlTestSuite are still not collected: pytest's python_classes default is ["Test"] (prefix match), so their test_* methods were never items and this diff does not silence any of them.
  • Script entrypoints unchanged: the markers are attribute writes; main() and if __name__ == "__main__" are untouched, so the three CI steps that run the scripts behave identically.
  • No pyproject.toml, setup.cfg, pytest.ini or conftest.py in the head tree (checked the full blob list via git/trees/c026ef43…?recursive=1), so nothing else re-enables collection here.
  • setup.py ships py_modules=["pymtml", "example"]; the test scripts are not in the wheel, so the new comments are not shipped artifacts.

Mechanical evidence — the four # ==== banners at test_sglang_compat.py:231/234/263/265 are context lines (the hunk starts at 268), i.e. pre-existing at the base commit, not introduced by this PR; .pre-commit-config.yaml:40 ignores E266 deliberately so banners stay legal here. Not a finding.

Gate — 10/10 hooks passed @ c026ef4.

Considered and rejected — scoping collection with --ignore/testpaths would also drop the two genuine tests living inside these files; moving the probes into a non-Test-prefixed class would move every call site in main(); a module-level __test__ = False would drop test_p2p_constants.

Could not verify — the author's runtime evidence (24 passed in 0.18s, the three scripts exiting 0 on the S5000 container): no MUSA/MTML host in this session and CI has not reported yet. Both Unit-test-job runs are pending.

This round ends auto-review for c026ef4; a later push starts a fresh cycle at round 1.

auto-review round 1/3 · verdict: clean

`make test` ran `pytest test_*.py`, which collected functions that are not
pytest cases (two helpers and six device probes that take their arguments from
`main()`), so it stopped with "fixture 'devices' not found": 24 passed,
8 errors.

The scripts behind the other CI steps had the opposite problem: they printed
every failed API and still exited 0, so a broken binding left CI green.
`test_error` and `test_api` counted nothing and their 77 return values were
dropped on the floor.

- Mark the helpers `__test__ = False` (pytest's documented opt-out), so
  `make test` is 24 passed.
- Count every check in `test_error` / `test_api`, print a summary, and exit 1
  when one failed. `Not Supported` is the platform answering rather than a
  defect, so it counts as skipped and keeps CI green.
- Fix the exception contract the pynvml side documents: `NVMLError` was a
  subclass of `MTMLError`, while `_mtmlCheckReturn` raises `MTMLError`, so
  `except pynvml.NVMLError` - the pattern `test_pynvml.py` itself uses - caught
  nothing and fell through to `except Exception`. MANUAL.md already documents
  `NVMLError = MTMLError`; the code now matches it, which also makes every
  `NVMLError_*` a subclass of `NVMLError` as pynvml guarantees.

Evidence on an MTT S5000 (vllm:v0.32.0-ph1-5.2.0-torch2.13.0):

  make test                  24 passed
  test_pymtml.py   exit 0    646 passed, 120 skipped (not supported), 0 failed
  test_pynvml.py   exit 0     57 passed,   2 skipped (not supported), 0 failed
  test_sglang_compat.py       exit 0

  nvmlDeviceGetMaxClockInfo (GRAPHICS): [NVMLError: Not Supported] (not supported)

Injecting a RuntimeError into one API makes `main()` return 1, so the gate
fires.
@yeahdongcn yeahdongcn changed the title fix(test): keep script helpers out of pytest collection fix(test): fail the run when a check fails, and fix the NVMLError contract Dec 3, 2026
@yeahdongcn
yeahdongcn merged commit 46084a5 into main Dec 4, 2026
0 of 2 checks passed
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