# TypeError: 不支持 '<' 在 'int' 和 'str' 实例之间进行比较

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

## 根因

向 `@pytest.mark.parametrize` 的 `ids=` 传入混合类型（如 ids=[1, 'two']）会使 pytest 在显示时排序它们，比较 int 与 str 时失败。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Cast all ids to strings:

@pytest.mark.parametrize('n', [1, 2, 3], ids=lambda n: f'case-{n}')
   ```
2. **** (90% 成功率)
   ```
   Provide a callable for ids that returns unique strings:

ids=lambda v: str(v).replace(' ', '_')
   ```

## 无效尝试

- **** — Works, but loses readability; long parameter values produce unreadable test IDs. (30% 失败率)
- **** — Sorting mixed types raises the same TypeError before pytest even sees it. (90% 失败率)
