python
type_error
ai_generated
true
TypeError: test_case() missing 1 required positional argument: 'expected'
ID: python/typeerror-test-case-missing-args
80%Fix Rate
86%Confidence
0Evidence
2024-04-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
Root Cause
Test function defined with required arguments but called without providing all arguments.
generic中文
测试函数定义了必需参数但调用时未提供所有参数。
Workarounds
-
95% success Provide the missing argument in the test call
def test_case(input, expected): ... ; test_case(5, 10)
-
98% success Use pytest parametrize to supply arguments
@pytest.mark.parametrize('input,expected', [(5,10)]) def test_case(input, expected): ...
Dead Ends
Common approaches that don't work:
-
Adding a default value to expected
50% fail
Default values may mask missing arguments but still cause logic errors if not intended.
-
Ignoring the error and rerunning
90% fail
The test will continue to fail until the argument is provided.