Skip to content

tests: fix parametrize patterns rejected by pytest 9.1.0#2212

Draft
leofang wants to merge 1 commit into
NVIDIA:mainfrom
leofang:leofang/fix-pytest9-collection-errors
Draft

tests: fix parametrize patterns rejected by pytest 9.1.0#2212
leofang wants to merge 1 commit into
NVIDIA:mainfrom
leofang:leofang/fix-pytest9-collection-errors

Conversation

@leofang

@leofang leofang commented Jun 14, 2026

Copy link
Copy Markdown
Member

Summary

main has been red since pytest 9.1.0 landed on PyPI — every Test linux-* / Test win-* matrix entry fails at pytest collection time, before any actual test runs. Two unrelated latent bugs in our test code, both tolerated by older pytest but rejected by pytest 9.1.0's stricter parametrize validation:

Bug 1: trailing comma in parametrize name (cuda_core)

cuda_core/tests/test_utils.py:151 had:

@pytest.mark.parametrize("in_arr,", _cpu_array_samples())

The , inside the string was a stray. pytest 9 splits names on comma, ends up with one name but 3-tuple values, and fails collection with:

in "parametrize" the number of names (1):
  ['in_arr']
must be equal to the number of values (3):
  (665115599, 23133, 0)

Fix: drop the trailing comma.

Bug 2: indirect=True override of a fixture-level parametrize (cuda_bindings)

cuda_bindings/tests/test_nvfatbin.py has an arch fixture parametrized with params=ARCHITECTURES. Two tests overrode it via @pytest.mark.parametrize("arch", ["sm_80"], indirect=True). pytest 9 now rejects this as:

duplicate parametrization of 'arch'

Fix: extract the CUBIN-building logic from the CUBIN fixture into a _build_cubin(arch) helper, drop the indirect override on the two affected tests, and call the helper directly with "sm_80" (preserving the original intent — those tests intentionally used only sm_80, since target arch "75" must not match the CUBIN's arch).

Backwards compatibility

Both fixes are pytest-version-agnostic — pip pin (pytest>=6.2.4) doesn't need to change. Verified by collecting against three pytest versions (minimal repros, included below for reproducibility):

pytest broken pattern 1 fixed 1 broken pattern 2 fixed 2
9.1.0 collection error clean collection error clean
9.0.2 clean (tolerant) clean clean (tolerant) clean
8.4.2 clean (tolerant) clean clean (tolerant) clean

Reference

Affected CI runs on main:

Same pattern on my open #2210: https://github.com/NVIDIA/cuda-python/actions/runs/27489049015 — 38 Run cuda.core tests failures + 23 Run cuda.bindings tests failures all stem from these two collection errors.

Two latent test-code bugs that older pytest tolerated but pytest 9.1.0
flags as collection errors, breaking every Test job on main since the
pytest 9.1.0 release:

* cuda_core/tests/test_utils.py:151 had a stray trailing comma in the
  `parametrize` name string (`"in_arr,"`). pytest 9 now splits names on
  comma and counts them, mismatching against the multi-element value
  tuples. Drop the comma.

* cuda_bindings/tests/test_nvfatbin.py had two tests using
  `@pytest.mark.parametrize("arch", ["sm_80"], indirect=True)` to
  override the fixture-level `arch` parametrization. pytest 9 now
  rejects this combination as "duplicate parametrization of 'arch'".
  Extract the CUBIN-building logic into a `_build_cubin(arch)` helper,
  drop the indirect override on the two tests, and call the helper
  inline with the hardcoded `"sm_80"` they need. Preserves intent (the
  override existed because target arch "75" must not match the CUBIN's
  arch).

Both fixes are pytest-version-agnostic; verified collecting cleanly
under pytest 9.1.0, 9.0.2, and 8.4.2 with minimal reproductions of
each pattern.
@copy-pr-bot

copy-pr-bot Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added cuda.bindings Everything related to the cuda.bindings module cuda.core Everything related to the cuda.core module labels Jun 14, 2026

@rwgk rwgk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I saw ... it can only get better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.bindings Everything related to the cuda.bindings module cuda.core Everything related to the cuda.core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants