# 类型错误：'generator' 对象不可调用

- **ID:** `python/pytest-fixture-return-generator`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在 pytest fixture 中使用了 yield 但忘记添加 @pytest.fixture 装饰器，导致生成器对象被当作函数调用。

## 版本兼容性

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

## 解决方案

1. **添加 @pytest.fixture 装饰器** (95% 成功率)
   ```
   @pytest.fixture
def my_fixture():
    yield 42
   ```
2. **在测试函数参数中接收 fixture** (90% 成功率)
   ```
   def test_func(my_fixture):
    assert my_fixture == 42
   ```

## 无效尝试

- **将 yield 改为 return，忽略 teardown** — 尝试将 fixture 改为普通函数并直接 return，但 fixture 需要 teardown 逻辑，导致资源泄漏 (70% 失败率)
- **在测试函数中直接调用 fixture 名称** — 在测试函数中直接调用 fixture 名称而不加括号，但 fixture 是生成器，无法被直接调用 (60% 失败率)
