python
config_error
ai_generated
true
DeprecationWarning: @pytest.yield_fixture 已弃用。请改用 @pytest.fixture;两者相同。
DeprecationWarning: @pytest.yield_fixture is deprecated. Use @pytest.fixture instead; they are the same.
ID: python/pytest-deprecation-yield-fixture
80%修复率
90%置信度
0证据数
2024-04-02首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
自 pytest 3.0 起,yield_fixture 是 fixture 的别名。在 pytest 7+ 中该别名会发出 DeprecationWarning,并将在未来移除。
English
Since pytest 3.0, yield_fixture is an alias of fixture. In pytest 7+ the alias emits a DeprecationWarning and will be removed.
解决方案
-
98% 成功率
# before @pytest.yield_fixture def client(): ... # after @pytest.fixture def client(): ...
-
90% 成功率
pyupgrade --py38-plus tests/**/*.py
无效尝试
常见但无效的做法:
-
70% 失败
Hides the warning but leaves the deprecated API in place; the fixture will break on the next major release.
-
65% 失败
Blocks upgrades and security patches across the whole test toolchain.