python
type_error
ai_generated
true
TypeError: ids must be a list of strings or callable, got int
ID: python/pytest-parametrize-ids-type
80%Fix Rate
85%Confidence
0Evidence
2025-01-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
pytest.parametrize的ids参数如果提供整数列表,pytest会报错,因为ids必须是字符串或可调用对象。
generic中文
pytest.parametrize的ids参数如果提供整数列表,pytest会报错,因为ids必须是字符串或可调用对象。
Workarounds
-
95% success
ids=lambda x: str(x)
-
90% success
ids=['case1', 'case2']
Dead Ends
Common approaches that don't work:
-
50% fail
转换后可能失去原始含义
-
40% fail
不提供ids会生成默认ID,但可能不明确