# DeprecationWarning: @pytest.yield_fixture 已弃用。请改用 @pytest.fixture；两者相同。

- **ID:** `python/pytest-deprecation-yield-fixture`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

自 pytest 3.0 起，yield_fixture 是 fixture 的别名。在 pytest 7+ 中该别名会发出 DeprecationWarning，并将在未来移除。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 7.x | active | — | — |
| 8.x | active | — | — |

## 解决方案

1. **** (98% 成功率)
   ```
   # before
@pytest.yield_fixture
def client(): ...

# after
@pytest.fixture
def client(): ...
   ```
2. **** (90% 成功率)
   ```
   pyupgrade --py38-plus tests/**/*.py
   ```

## 无效尝试

- **** — Hides the warning but leaves the deprecated API in place; the fixture will break on the next major release. (70% 失败率)
- **** — Blocks upgrades and security patches across the whole test toolchain. (65% 失败率)
