Skip to content

Commit d9bb37c

Browse files
authored
tests: fix duplicate parametrization rejected by pytest 9.1.0 (#2227)
Backport of #2212, scoped down to the cuda_bindings/tests/test_nvfatbin.py portion that applies to 12.9.x. The cuda_core/tests/test_utils.py portion of #2212 (the trailing-comma-in-parametrize-name fix) does not apply here because the 12.9.x version of that test file does not have the bug — its parametrize uses two names matching tuple values. What is fixed (verbatim from #2212): 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.1.0 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). Closes #2226. Hunk body verified identical to the corresponding hunk in #2212 (commit a9156b6).
1 parent c5c1db1 commit d9bb37c

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

cuda_bindings/tests/test_nvfatbin.py

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

124124

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

144143

144+
@pytest.fixture
145+
def CUBIN(arch):
146+
return _build_cubin(arch)
147+
148+
145149
# create a valid LTOIR input for testing
146150
@pytest.fixture
147151
def LTOIR(arch):
@@ -261,11 +265,11 @@ def test_nvfatbin_add_ptx(PTX, arch):
261265
nvfatbin.destroy(handle)
262266

263267

264-
@pytest.mark.parametrize("arch", ["sm_80"], indirect=True)
265-
def test_nvfatbin_add_cubin_ELF_SIZE_MISMATCH(CUBIN, arch):
268+
def test_nvfatbin_add_cubin_ELF_SIZE_MISMATCH():
269+
cubin = _build_cubin("sm_80")
266270
handle = nvfatbin.create([], 0)
267271
with pytest.raises(nvfatbin.nvFatbinError, match="ERROR_ELF_ARCH_MISMATCH"):
268-
nvfatbin.add_cubin(handle, CUBIN, len(CUBIN), "75", "inc")
272+
nvfatbin.add_cubin(handle, cubin, len(cubin), "75", "inc")
269273

270274
nvfatbin.destroy(handle)
271275

@@ -282,11 +286,11 @@ def test_nvfatbin_add_cubin(CUBIN, arch):
282286
nvfatbin.destroy(handle)
283287

284288

285-
@pytest.mark.parametrize("arch", ["sm_80"], indirect=True)
286-
def test_nvfatbin_add_cubin_ELF_ARCH_MISMATCH(CUBIN, arch):
289+
def test_nvfatbin_add_cubin_ELF_ARCH_MISMATCH():
290+
cubin = _build_cubin("sm_80")
287291
handle = nvfatbin.create([], 0)
288292
with pytest.raises(nvfatbin.nvFatbinError, match="ERROR_ELF_ARCH_MISMATCH"):
289-
nvfatbin.add_cubin(handle, CUBIN, len(CUBIN), "75", "inc")
293+
nvfatbin.add_cubin(handle, cubin, len(cubin), "75", "inc")
290294

291295
nvfatbin.destroy(handle)
292296

0 commit comments

Comments
 (0)