python
type_error
ai_generated
true
TypeError: test_func() missing 1 required positional argument: 'b'
ID: python/pytest-parametrize-arguments-count
80%Fix Rate
93%Confidence
0Evidence
2025-04-12First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
Root Cause
在 @pytest.mark.parametrize 中提供的参数数量与测试函数参数数量不一致。
generic中文
在 @pytest.mark.parametrize 中提供的参数数量与测试函数参数数量不一致。
Workarounds
-
98% success 确保参数数量匹配
@pytest.mark.parametrize('a,b', [(1,2), (3,4)]) def test_func(a,b): pass -
90% success 使用单个元组参数
@pytest.mark.parametrize('args', [(1,2), (3,4)]) def test_func(args): a,b = args
Dead Ends
Common approaches that don't work:
-
使用 *args
60% fail
尝试将测试函数参数改为 *args,但失去了类型检查
-
提供错误格式
70% fail
尝试在 parametrize 中只提供一个参数元组,但忘记解包