From 2a6603203c500d91af041b40b559b1c5fc30010c Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Mon, 15 Jun 2026 23:03:43 +0000 Subject: [PATCH] tests: fix duplicate parametrization rejected by pytest 9.1.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 a9156b6207). --- cuda_bindings/tests/test_nvfatbin.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/cuda_bindings/tests/test_nvfatbin.py b/cuda_bindings/tests/test_nvfatbin.py index db6281a575c..400de0c4b79 100644 --- a/cuda_bindings/tests/test_nvfatbin.py +++ b/cuda_bindings/tests/test_nvfatbin.py @@ -122,8 +122,7 @@ def nvcc_smoke(tmpdir) -> str: return nvcc -@pytest.fixture -def CUBIN(arch): +def _build_cubin(arch): def CHECK_NVRTC(err): if err != nvrtc.nvrtcResult.NVRTC_SUCCESS: raise RuntimeError(repr(err)) @@ -142,6 +141,11 @@ def CHECK_NVRTC(err): return cubin +@pytest.fixture +def CUBIN(arch): + return _build_cubin(arch) + + # create a valid LTOIR input for testing @pytest.fixture def LTOIR(arch): @@ -261,11 +265,11 @@ def test_nvfatbin_add_ptx(PTX, arch): nvfatbin.destroy(handle) -@pytest.mark.parametrize("arch", ["sm_80"], indirect=True) -def test_nvfatbin_add_cubin_ELF_SIZE_MISMATCH(CUBIN, arch): +def test_nvfatbin_add_cubin_ELF_SIZE_MISMATCH(): + cubin = _build_cubin("sm_80") handle = nvfatbin.create([], 0) with pytest.raises(nvfatbin.nvFatbinError, match="ERROR_ELF_ARCH_MISMATCH"): - nvfatbin.add_cubin(handle, CUBIN, len(CUBIN), "75", "inc") + nvfatbin.add_cubin(handle, cubin, len(cubin), "75", "inc") nvfatbin.destroy(handle) @@ -282,11 +286,11 @@ def test_nvfatbin_add_cubin(CUBIN, arch): nvfatbin.destroy(handle) -@pytest.mark.parametrize("arch", ["sm_80"], indirect=True) -def test_nvfatbin_add_cubin_ELF_ARCH_MISMATCH(CUBIN, arch): +def test_nvfatbin_add_cubin_ELF_ARCH_MISMATCH(): + cubin = _build_cubin("sm_80") handle = nvfatbin.create([], 0) with pytest.raises(nvfatbin.nvFatbinError, match="ERROR_ELF_ARCH_MISMATCH"): - nvfatbin.add_cubin(handle, CUBIN, len(CUBIN), "75", "inc") + nvfatbin.add_cubin(handle, cubin, len(cubin), "75", "inc") nvfatbin.destroy(handle)