# 名称错误：名称 'setup_method' 未定义

- **ID:** `python/nameerror-name-not-defined`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

测试类使用了如 setup_method 的方法但未定义，或拼写错误。

## 版本兼容性

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

## 解决方案

1. **Define setup_method as class method** (95% 成功率)
   ```
   class TestClass:
    def setup_method(self):
        pass
   ```
2. **Use pytest fixture instead** (90% 成功率)
   ```
   @pytest.fixture(autouse=True)
def setup_method(self):
    pass
   ```

## 无效尝试

- **Defining setup_method inside test function** — setup_method should be a method of the test class, not nested inside a test. (70% 失败率)
- **Using setup_method as a fixture** — setup_method is a unittest convention; pytest uses fixtures instead. (50% 失败率)
