# TypeError: TestCase.__init__() 缺少 1 个必需的位置参数: 'methodName'

- **ID:** `python/unittest-testcase-requires-method`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

直接实例化 `unittest.TestCase` 子类（如 `MyTest()`），而不是让测试运行器实例化，或忘记传入方法名。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.9 | active | — | — |
| 3.12 | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   Use the test runner instead of instantiating directly:
import unittest
unittest.main()
# or
loader = unittest.TestLoader()
suite = loader.loadTestsFromTestCase(MyTest)
unittest.TextTestRunner().run(suite)
   ```
2. **** (85% 成功率)
   ```
   If you must instantiate: `case = MyTest('test_something')` then `case.run(result)`.
   ```

## 无效尝试

- **** — Creates an invalid test case that fails later at run time with a different error. (60% 失败率)
- **** — Still raises because TestCase requires methodName. (70% 失败率)
