Skip to content

Mark yield_fixture as deprecated#14340

Closed
MarcoGorelli wants to merge 1 commit intopytest-dev:mainfrom
MarcoGorelli:mark-yield_fixture-deprecated
Closed

Mark yield_fixture as deprecated#14340
MarcoGorelli wants to merge 1 commit intopytest-dev:mainfrom
MarcoGorelli:mark-yield_fixture-deprecated

Conversation

@MarcoGorelli
Copy link
Copy Markdown
Contributor

yield_fixtureis deprecated, is it ok to use thedeprecated` decorator on it?

pytest/src/_pytest/fixtures.py

Lines 1434 to 1435 in 959cd47

.. deprecated:: 3.0
Use :py:func:`pytest.fixture` directly instead.

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Mar 30, 2026
@MarcoGorelli MarcoGorelli force-pushed the mark-yield_fixture-deprecated branch 2 times, most recently from 928816a to 646d5e2 Compare March 30, 2026 16:12
@MarcoGorelli MarcoGorelli force-pushed the mark-yield_fixture-deprecated branch from 646d5e2 to 61f7b83 Compare March 30, 2026 16:19
@MarcoGorelli MarcoGorelli marked this pull request as ready for review March 30, 2026 16:25
Copy link
Copy Markdown
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, however the hitch here is that @deprecated also emits a runtime warning, so with this we will be emitting 2 runtime deprecation warnings. You could say, let's remove the existing runtime deprecation, the problem with that is that our compat for Python < 3.13 doesn't emit a runtime warning. This has been fine so far since we only use @deprecated under TYPE_CHECKING, but here it's not.

So either

  • We backport @deprecated runtime behavior. But the Python code is about a 100 lines, a bit too much I think.
  • We move the @deprecated under TYPE_CHECKING (duplicating def yield_fixture), that's a bit ugly though.
  • We leave as is for now.



@deprecated(
"pytest.yield_fixture is deprecated, use pytest.fixture to access configuration values instead.",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the same text as the existing runtime deprecation.

Suggested change
"pytest.yield_fixture is deprecated, use pytest.fixture to access configuration values instead.",
"@pytest.yield_fixture is deprecated. Use @pytest.fixture instead; they are the same.",

@MarcoGorelli
Copy link
Copy Markdown
Contributor Author

thanks for your response!

We leave as is for now.

sure, happy to do this!

@The-Compiler
Copy link
Copy Markdown
Member

I'd go for (trivial) option 4: Pass category=None into warnings.deprecated() so that it doesn't show a runtime warning, and keep our own.

I think there is a lot of value in having deprecations visible statically, so I opened #14342 to that effect.

Thanks @MarcoGorelli for getting the ball rolling!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants