python
type_error
ai_generated
true
TypeError: ids must be a list or callable, got <class 'str'>
ID: python/pytest-fixture-params-ids-type
80%Fix Rate
90%Confidence
0Evidence
2025-07-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
Root Cause
在 parametrize 中传递 ids 参数时使用了字符串而不是列表或函数。
generic中文
在 parametrize 中传递 ids 参数时使用了字符串而不是列表或函数。
Workarounds
-
98% success 使用列表
@pytest.mark.parametrize('x', [1,2], ids=['a','b']) -
95% success 使用可调用对象
@pytest.mark.parametrize('x', [1,2], ids=lambda x: f'id_{x}')
Dead Ends
Common approaches that don't work:
-
ids='a,b'
40% fail
尝试将字符串转换为列表但忘记括号
-
ids=lambda x: 'id'
30% fail
尝试使用 lambda 但 lambda 返回字符串而非列表