python
data_error
ai_generated
true
ValueError: duplicate parameter set with id 'case_1'
ID: python/pytest-parametrize-id-collision
80%Fix Rate
86%Confidence
0Evidence
2024-07-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
Using the same ID for multiple parametrized cases without unique IDs.
generic中文
为多个参数化用例使用相同的 ID,而没有唯一 ID。
Workarounds
-
99% success
@pytest.mark.parametrize('arg', [1, 2], ids=['case_1', 'case_2']) -
95% success
def id_func(val): return f'case_{val}' @pytest.mark.parametrize('arg', [1, 2], ids=id_func)
Dead Ends
Common approaches that don't work:
-
40% fail
Pytest will auto-generate IDs, but they may not be descriptive.
-
100% fail
This still causes duplicate IDs.