python
config_error
ai_generated
true
DeprecationWarning: @pytest.yield_fixture is deprecated. Use @pytest.fixture instead; they are the same.
ID: python/pytest-deprecation-yield-fixture
80%Fix Rate
90%Confidence
0Evidence
2024-04-02First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
Since pytest 3.0, yield_fixture is an alias of fixture. In pytest 7+ the alias emits a DeprecationWarning and will be removed.
generic中文
自 pytest 3.0 起,yield_fixture 是 fixture 的别名。在 pytest 7+ 中该别名会发出 DeprecationWarning,并将在未来移除。
Workarounds
-
98% success
# before @pytest.yield_fixture def client(): ... # after @pytest.fixture def client(): ...
-
90% success
pyupgrade --py38-plus tests/**/*.py
Dead Ends
Common approaches that don't work:
-
70% fail
Hides the warning but leaves the deprecated API in place; the fixture will break on the next major release.
-
65% fail
Blocks upgrades and security patches across the whole test toolchain.