Skip to content

Commit a9156b6

Browse files
authored
tests: fix parametrize patterns rejected by pytest 9.1.0 (#2212)
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.
1 parent ae1617d commit a9156b6

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

cuda_bindings/tests/test_nvfatbin.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ def nvcc_smoke(tmpdir) -> str:
121121
return nvcc
122122

123123

124-
@pytest.fixture
125-
def CUBIN(arch):
124+
def _build_cubin(arch):
126125
def CHECK_NVRTC(err):
127126
if err != nvrtc.nvrtcResult.NVRTC_SUCCESS:
128127
raise RuntimeError(repr(err))
@@ -141,6 +140,11 @@ def CHECK_NVRTC(err):
141140
return cubin
142141

143142

143+
@pytest.fixture
144+
def CUBIN(arch):
145+
return _build_cubin(arch)
146+
147+
144148
# create a valid LTOIR input for testing
145149
@pytest.fixture
146150
def LTOIR(arch):
@@ -259,11 +263,11 @@ def test_nvfatbin_add_ptx(PTX, arch):
259263
nvfatbin.destroy(handle)
260264

261265

262-
@pytest.mark.parametrize("arch", ["sm_80"], indirect=True)
263-
def test_nvfatbin_add_cubin_ELF_SIZE_MISMATCH(CUBIN, arch):
266+
def test_nvfatbin_add_cubin_ELF_SIZE_MISMATCH():
267+
cubin = _build_cubin("sm_80")
264268
handle = nvfatbin.create([], 0)
265269
with pytest.raises(nvfatbin.nvFatbinError, match="ERROR_ELF_ARCH_MISMATCH"):
266-
nvfatbin.add_cubin(handle, CUBIN, len(CUBIN), "75", "inc")
270+
nvfatbin.add_cubin(handle, cubin, len(cubin), "75", "inc")
267271

268272
nvfatbin.destroy(handle)
269273

@@ -280,11 +284,11 @@ def test_nvfatbin_add_cubin(CUBIN, arch):
280284
nvfatbin.destroy(handle)
281285

282286

283-
@pytest.mark.parametrize("arch", ["sm_80"], indirect=True)
284-
def test_nvfatbin_add_cubin_ELF_ARCH_MISMATCH(CUBIN, arch):
287+
def test_nvfatbin_add_cubin_ELF_ARCH_MISMATCH():
288+
cubin = _build_cubin("sm_80")
285289
handle = nvfatbin.create([], 0)
286290
with pytest.raises(nvfatbin.nvFatbinError, match="ERROR_ELF_ARCH_MISMATCH"):
287-
nvfatbin.add_cubin(handle, CUBIN, len(CUBIN), "75", "inc")
291+
nvfatbin.add_cubin(handle, cubin, len(cubin), "75", "inc")
288292

289293
nvfatbin.destroy(handle)
290294

cuda_core/tests/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def _cpu_array_samples():
148148
return samples
149149

150150

151-
@pytest.mark.parametrize("in_arr,", _cpu_array_samples())
151+
@pytest.mark.parametrize("in_arr", _cpu_array_samples())
152152
class TestViewCPU:
153153
def test_args_viewable_as_strided_memory_cpu(self, in_arr):
154154
@args_viewable_as_strided_memory((0,))

0 commit comments

Comments
 (0)