# ValueError: 在 parametrize 中重复的 'test_id'

- **ID:** `python/pytest-parametrize-id-duplicate`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

两个或多个参数化用例具有相同的 ID，要么通过 ids 显式设置，要么从相同的参数值自动生成。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 7.x | active | — | — |
| 8.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   @pytest.mark.parametrize('x', [1, 1], ids=['first', 'second'])
def test_foo(x): ...
   ```
2. **** (90% 成功率)
   ```
   def idfn(val):
    return f'val-{val}-{uuid.uuid4()}'

@pytest.mark.parametrize('x', [1, 1], ids=idfn)
   ```

## 无效尝试

- **** — If the parameter values are identical, pytest still generates duplicate IDs. (70% 失败率)
- **** — The duplication is within the same test's parametrization, not across tests. (90% 失败率)
