python
type_error
ai_generated
true
类型错误:test_case() 缺少 1 个必需的位置参数:'expected'
TypeError: test_case() missing 1 required positional argument: 'expected'
ID: python/typeerror-test-case-missing-args
80%修复率
86%置信度
0证据数
2024-04-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
根因分析
测试函数定义了必需参数但调用时未提供所有参数。
English
Test function defined with required arguments but called without providing all arguments.
解决方案
-
95% 成功率 Provide the missing argument in the test call
def test_case(input, expected): ... ; test_case(5, 10)
-
98% 成功率 Use pytest parametrize to supply arguments
@pytest.mark.parametrize('input,expected', [(5,10)]) def test_case(input, expected): ...
无效尝试
常见但无效的做法:
-
Adding a default value to expected
50% 失败
Default values may mask missing arguments but still cause logic errors if not intended.
-
Ignoring the error and rerunning
90% 失败
The test will continue to fail until the argument is provided.