python type_error ai_generated true

TypeError: ids must be a list of strings or callable, got int

ID: python/pytest-parametrize-ids-type

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2025-01-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
7.x active
8.x active

Root Cause

pytest.parametrize的ids参数如果提供整数列表,pytest会报错,因为ids必须是字符串或可调用对象。

generic

中文

pytest.parametrize的ids参数如果提供整数列表,pytest会报错,因为ids必须是字符串或可调用对象。

Workarounds

  1. 95% success
    ids=lambda x: str(x)
  2. 90% success
    ids=['case1', 'case2']

Dead Ends

Common approaches that don't work:

  1. 50% fail

    转换后可能失去原始含义

  2. 40% fail

    不提供ids会生成默认ID,但可能不明确