python
data_error
ai_generated
true
值错误:id 为 'case_1' 的重复参数集
ValueError: duplicate parameter set with id 'case_1'
ID: python/pytest-parametrize-id-collision
80%修复率
86%置信度
0证据数
2024-07-22首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
为多个参数化用例使用相同的 ID,而没有唯一 ID。
English
Using the same ID for multiple parametrized cases without unique IDs.
解决方案
-
99% 成功率
@pytest.mark.parametrize('arg', [1, 2], ids=['case_1', 'case_2']) -
95% 成功率
def id_func(val): return f'case_{val}' @pytest.mark.parametrize('arg', [1, 2], ids=id_func)
无效尝试
常见但无效的做法:
-
40% 失败
Pytest will auto-generate IDs, but they may not be descriptive.
-
100% 失败
This still causes duplicate IDs.