Skip to content

fixtures: deprecate FixtureDef.has_location and None global fixture visibility#14567

Open
bluetech wants to merge 3 commits into
mainfrom
more-visibility-deprecate
Open

fixtures: deprecate FixtureDef.has_location and None global fixture visibility#14567
bluetech wants to merge 3 commits into
mainfrom
more-visibility-deprecate

Conversation

@bluetech
Copy link
Copy Markdown
Member

@bluetech bluetech commented Jun 6, 2026

This PR is stacked on:

The first commit deprecates FixtureDef.has_location. With #14566 it is no longer needed, and use of it is probably wrong.

The second commit removes internal use of None global visibility, replaced by Session visibility.

The third commit deprecates global None visibility (extends the nodeid/baseid deprecation).

With this (the non-deprecated parts of) _register_fixture are neat and clean and this readies us to expose a pytest.register_fixture (next commit in the stack).

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Jun 6, 2026
@RonnyPfannschmidt
Copy link
Copy Markdown
Member

i wonder if this has actual external users and which those are to decide actual removal later

@bluetech bluetech force-pushed the visibility-override branch 2 times, most recently from 41bc25f to 7186cd4 Compare June 7, 2026 18:32
Base automatically changed from visibility-override to main June 7, 2026 18:50
bluetech added 3 commits June 7, 2026 21:51
has_location was used to determine the fixture override order, pushing
fixturedefs with no location to the front of the override chain. Now
that the override order is determined by the fixtures' visibility in the
collection tree, the attribute is no longer needed.

Turn it into a property that emits a PytestRemovedIn10Warning, backed by
the private _has_location attribute, and document the deprecation.
…ility instead of None

Let's get rid of the `None` global visibility. Use `Session` which is
functionality equivalent instead.

- Allows us to remove an annoying special case from the fixture core.
- Allows a cleaner public `register_fixture` interface (upcoming).

There was previously a distinction between "has location" (e.g. conftest
plugins) and "no location" (e.g. external plugins), but it's no longer
needed after recent changes. Since initial conftest plugins are always
registered after core & external plugins, the override chain order is
maintained.
The nodeid-visibility/baseid deprecation previously allowed None
(global) visibility. But this visibility is no longer needed, should use
Session visibility instead. So let's include it in the deprecation as
well, this way we can have a clean break in pytest 10.
@bluetech bluetech force-pushed the more-visibility-deprecate branch from b50559e to 547eb13 Compare June 7, 2026 18:52
@bluetech
Copy link
Copy Markdown
Member Author

bluetech commented Jun 7, 2026

i wonder if this has actual external users and which those are to decide actual removal later

I looked at my pytest plugin corpus (checkouts of ~700 plugins).

For has_location I found 1 hit:
https://github.com/willemt/pytest-asyncio-cooperative/blob/580309e280093132e919c25c8adb4ecdb59b7e7a/pytest_asyncio_cooperative/fixtures.py#L41-L43.
They will need to update.

For _register_fixture I found 1 hit:
https://github.com/pytest-dev/pytest-bdd/blob/234fdeb230da3cbeae32ec77f2125c2f0ed7e4bd/src/pytest_bdd/compat.py#L29-L33
The nodeid itself is deprecated, but doesn't use None visibility so update should be straightforward.

For parsefactories I found 3 hits:
pytest-describe/src/pytest_describe/plugin.py:105: self.session._fixturemanager.parsefactories(self)
pytest-eucalyptus/pytest_eucalyptus/plugin.py:79: self.session._fixturemanager.parsefactories(self, unittest=True)
These two seem fine (passing a Node).
https://github.com/cielavenir/pytest-session-fixture-globalize/blob/37fb60981c2825e5c465f2c4816708b6e85866be/pytest_session_fixture_globalize/pytest_session_fixture_globalize.py
Will definitely need update, but it wholly replaces parsefactories, which is deep in "unsupported" territory.

Finally, for FixtureDef ctor I found a few hits with a lot of interesting plugins, but these are the relevant ones:
https://github.com/pytest-dev/pytest-bdd/blob/234fdeb230da3cbeae32ec77f2125c2f0ed7e4bd/src/pytest_bdd/compat.py#L54-L61
Only used for pytest<8.1, not relevant.
https://github.com/Flowminder/pytest-airflow/blob/31b1d2ccd3e3f20155a8bb63d02d38578ef7a4ac/pytest_airflow/plugin.py
Repo is archived, I think it's abandoned. Uses a bunch of internal details, probably already broken.
https://github.com/pytest-dev/pytest-factoryboy/blob/76dc1c106fccf6ce3841e93d4198045e128e279a/src/pytest_factoryboy/fixture.py
Does lots of fixture stuff, though I don't see anything that would break.
https://github.com/voronind/pytest-missing-fixtures/blob/c272672900657f275c9b9acf8c724d59d5ea51f5/pytest_missing_fixtures.py#L56-L75
Will need to update for baseid but doesn't use None.

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.

2 participants