python
config_error
ai_generated
true
ValueError: 在 parametrize 中重复的 'test_id'
ValueError: duplicate 'test_id' in parametrize
ID: python/pytest-parametrize-id-duplicate
80%修复率
85%置信度
0证据数
2024-06-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
两个或多个参数化用例具有相同的 ID,要么通过 ids 显式设置,要么从相同的参数值自动生成。
English
Two or more parametrized cases have the same ID, either explicitly set via ids or generated automatically from identical parameter values.
解决方案
-
95% 成功率
@pytest.mark.parametrize('x', [1, 1], ids=['first', 'second']) def test_foo(x): ... -
90% 成功率
def idfn(val): return f'val-{val}-{uuid.uuid4()}' @pytest.mark.parametrize('x', [1, 1], ids=idfn)
无效尝试
常见但无效的做法:
-
70% 失败
If the parameter values are identical, pytest still generates duplicate IDs.
-
90% 失败
The duplication is within the same test's parametrization, not across tests.